0

我需要在需要部署在主网上的新合约中调用我部署的 ERC20 代币的传输函数。我想知道这是否可行,或者需要大量的汽油,进而需要高额的交易费用。

4

1 回答 1

0

是的,这是可行的——这是合约相互交互的方式。一般来说,我们在调用合约中使用一个接口:

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)
        }
    }
于 2020-08-21T21:47:52.573 回答