|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
- 聯準會維持利率的決定,加上中東衝突,影響了比特幣的價格。分析近期趨勢和市場反應。
-
-
-
-
-
-

































