|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Circle 的智能合约平台通过带有 SDK 的智能合约简化了 ETH 到 USDC 的兑换,以便于部署和交互。

integrate Circle's Smart Contract Platform into their dApps or applications.
将 Circle 的智能合约平台集成到他们的 dApp 或应用程序中。
Prerequisites
先决条件
Before proceeding with the ETH to USDC swaps using Circle's platform, ensure the following prerequisites are met:
在使用 Circle 平台进行 ETH 到 USDC 互换之前,请确保满足以下先决条件:
Node.js (v16.14.2 or later) is installed on your local machine.
Node.js(v16.14.2 或更高版本)安装在您的本地计算机上。
You have obtained a Circle Access Key and Secret Key. To learn how to generate these keys, refer to the Circle Developer Hub.
您已获得 Circle Access Key 和 Secret Key。要了解如何生成这些密钥,请参阅 Circle 开发者中心。
Node Package Manager (NPM) is installed.
已安装节点包管理器 (NPM)。
Writing the Smart Contract
编写智能合约
The smart contract will interact with Uniswap to perform the token swaps. Upon depositing ETH, it is converted to Wrapped ETH (WETH) and can be swapped for USDC using Uniswap's protocol.
智能合约将与 Uniswap 交互以执行代币交换。存入 ETH 后,它会转换为 Wrapped ETH (WETH),并可以使用 Uniswap 协议兑换为 USDC。
Here's the contract code:
这是合约代码:
// SPDX-License-Identifier: GPL-3.0
// SPDX 许可证标识符:GPL-3.0
pragma solidity 0.8.17;
杂注坚固性 0.8.17;
interface IUniswapV2Router02 {
接口 IUniswapV2Router02 {
function swapExactETHForTokens(
函数 swapExactETHForTokens(
uint256 amountOutMin,
uint256 金额输出最小值,
address[] calldata path,
地址[]调用数据路径,
address to,
地址,
uint256 deadline
uint256 截止日期
) external payable returns (uint256[] memory amounts);
) 外部应付收益(uint256[] 内存量);
function WETH() external pure returns (address);
函数 WETH() 外部纯返回(地址);
}
}
contract EthToUsdcSwap {
合约 EthToUsdcSwap {
IUniswapV2Router02 private constant uniswapRouter = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F248cF);
IUniswapV2Router02 私有常量 uniswapRouter = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F248cF);
address private constant usdcAddress = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48;
地址私有常量usdcAddress = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48;
function swapEthToUsdc(
函数 swapEthToUsdc(
uint256 minUsdcAmount,
uint256 minUsdcAmount,
address to
地址至
) external payable {
) 外部应付{
address[] memory path = new address[](2);
地址[]内存路径=新地址[](2);
path[0] = uniswapRouter.WETH();
路径[0] = uniswapRouter.WETH();
path[1] = usdcAddress;
路径[1] = usdc地址;
uniswapRouter.swapExactETHForTokens{value: msg.value}(
uniswapRouter.swapExactETHForTokens{值:msg.value}(
minUsdcAmount,
最小美元金额,
path,
小路,
to,
到,
block.timestamp + 300
区块时间戳 + 300
);
);
}
}
}
}
Compiling the Smart Contract
编译智能合约
Use Remix IDE to compile the contract and obtain the ABI (Application Binary Interface) and bytecode.
使用Remix IDE编译合约并获取ABI(应用程序二进制接口)和字节码。
Deploying the Smart Contract
部署智能合约
Use Circle's SDK to deploy the compiled contract. Before proceeding, ensure you have set the CIRCLE_ACCESS_KEY and CIRCLE_SECRET_KEY environment variables in your terminal or script.
使用Circle的SDK来部署编译好的合约。在继续之前,请确保您已在终端或脚本中设置 CIRCLE_ACCESS_KEY 和 CIRCLE_SECRET_KEY 环境变量。
Here's an example command:
这是一个示例命令:
npx circle-smart-contracts deploy \
npx 圈智能合约部署 \
--abi="./build/contracts/EthToUsdcSwap.sol/EthToUsdcSwap.json" \
--abi="./build/contracts/EthToUsdcSwap.sol/EthToUsdcSwap.json" \
--bytecode="0x$(cat build/contracts/EthToUsdcSwap.sol/EthToUsdcSwap.bin)" \
--bytecode="0x$(cat build/contracts/EthToUsdcSwap.sol/EthToUsdcSwap.bin)" \
--chain="ethereum" \
--chain="以太坊" \
--constructor-args='[]' \
--constructor-args='[]' \
--output-dir="./output"
--output-dir="./输出"
Upon successful deployment, you will receive a contractId and transactionId for future reference.
部署成功后,您将收到contractId和transactionId以供将来参考。
Interacting with the Deployed Contract
与已部署的合约交互
To perform token swaps using the deployed contract:
要使用已部署的合约执行代币交换:
Before proceeding, ensure you have set the CIRCLE_ACCESS_KEY, CIRCLE_SECRET_KEY, CIRCLE_CONTRACT_ID, and CIRCLE_CHAIN environment variables in your terminal or script.
在继续之前,请确保您已在终端或脚本中设置 CIRCLE_ACCESS_KEY、CIRCLE_SECRET_KEY、CIRCLE_CONTRACT_ID 和 CIRCLE_CHAIN 环境变量。
Here's an example command to swap 0.1 ETH to USDC and send the tokens to the specified address:
以下是将 0.1 ETH 交换为 USDC 并将代币发送到指定地址的示例命令:
npx circle-smart-contracts interact \
npx 圈智能合约交互 \
--function="swapEthToUsdc" \
--function =“swapEthToUsdc”\
--args='[0.1, "0x$(circle-wallet)"]' \
--args='[0.1, "0x$(圆钱包)"]' \
--output-dir="./output"
--output-dir="./输出"
This command will perform a token swap of 0.1 ETH to USDC and send the swapped USDC tokens to your Circle Pay wallet, which can be viewed in the Circle Developer Hub.
此命令将执行 0.1 ETH 到 USDC 的代币兑换,并将兑换后的 USDC 代币发送到您的 Circle Pay 钱包,您可以在 Circle 开发者中心查看该钱包。
Conclusion
结论
Circle's Smart Contract Platform offers a streamlined solution for deploying and managing smart contracts to swap ETH to USDC. By leveraging Circle's SDK, developers can easily execute transactions on the blockchain to integrate Circle's services into their dApps or applications.
Circle 的智能合约平台提供了一个简化的解决方案,用于部署和管理智能合约以将 ETH 兑换为 USDC。通过利用 Circle 的 SDK,开发人员可以轻松地在区块链上执行交易,将 Circle 的服务集成到他们的 dApp 或应用程序中。
免责声明:info@kdj.com
所提供的信息并非交易建议。根据本文提供的信息进行的任何投资,kdj.com不承担任何责任。加密货币具有高波动性,强烈建议您深入研究后,谨慎投资!
如您认为本网站上使用的内容侵犯了您的版权,请立即联系我们(info@kdj.com),我们将及时删除。
-
- 比特币、eCash 分叉和空投动态:深入探讨加密货币的最新争议
- 2026-05-03 00:52:02
- 探索最近的 eCash 分叉、其作为高风险空投的分类,以及对比特币和加密生态系统的更广泛影响。
-
-
- 美联储维持利率稳定,地缘政治紧张局势引发比特币价格下跌
- 2026-05-01 04:04:38
- 美联储维持利率的决定,加上中东冲突,影响了比特币的价格。分析近期趋势和市场反应。
-
-
-
-
-
-

































