Reputation: 26
I need to call the transfer function of my deployed ERC20 token in a new contract which needs to be deployed on mainnet. I want to know would it be feasible or it will be requiring a lot of gas and in turns high transaction charges.
Upvotes: 0
Views: 670
Reputation: 1824
Yes, it's feasible - it's the way contracts interact with eachother. In general, we use an interface in the calling contract:
pragma solidity ^0.5.0;
// Define an interface to the contract you want to call. Only need function signatures
interface YourErc20Contract {
function transfer(address recipient, uint amount) external;
}
contract CallingContract {
address your_erc20_address = 0x..... // called contract address here
address recipient = 0x.... // arguments for the function call
uint amount = 2
// Call the function on the other contract using the interface
function remoteCall(address recipient, uint amount) public {
YourErc20Contract(your_erc20_address).transfer(recipient, amount)
}
}
Upvotes: 0