如何解决从主网以太坊上的其他智能合约调用已部署合约的功能就天然气成本而言是否可行?
我需要在需要在主网上部署的新合同中调用已部署的ERC20令牌的传递函数。我想知道这将是可行的,还是会需要大量的汽油,从而导致高昂的交易费用。
解决方法
是的,这是可行的-这是合同彼此交互的方式。通常,我们在调用合同中使用一个接口:
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)
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。