External ERC-20 token implementation into my contract

William: 2 weeks ago

I want to implement USDC into my contract which is currently using ETH. I know I need to implement ERC20 interface in order to let my contract know which functions it should expect. But how should I continue? I suppose I need to take USDC contract address and do something with it. I couldn't find what exactly should I do.

The goal is to be able to accept USDC and display its balance. Any useful links, please? (I am new to smart contract development)

Noah: 2 weeks ago

you tell your contract that the contract that lives at the USDC token address is an ERC20 token like this IERC20 token = IERC20(USDCContractAddress) and then you use its function like this 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'

General syntax for using interfaces like that is

// 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