Solidity

在我的契約中實施外部 ERC-20 代幣

  • August 11, 2021

我想在我目前使用 ETH 的合約中實施 USDC。我知道我需要實現 ERC20 介面,以便讓我的合約知道它應該期望哪些功能。但我應該如何繼續?我想我需要獲取 USDC 合約地址並對其進行處理。我找不到我到底應該做什麼。

目標是能夠接受 USDC 並顯示其餘額。請問有什麼有用的連結嗎?(我是智能合約開發的新手)

你告訴你的合約,位於 USDC 代幣地址的合約是這樣的 ERC20 代幣IERC20 token = IERC20(USDCContractAddress) ,然後你像這樣使用它的功能token.transferFrom(user, address (this), amount); // This is an example that takes 'amount' of USDC from 'user' and send it to the contract address, assuming the users allowance is > to 'amount'

使用這樣的介面的一般語法是

// Declaring 
YourInterface contract = YourInterface(contractAddress);
// Using 
contract.yourFunction(input1, input2); // 'yourFunction' must be in 'YourInterface' and 'input1' and 'input2 must be of correct types or your contract wont compile

引用自:https://ethereum.stackexchange.com/questions/106952