18

用自己部署的合约调用pancake购买代币,发现value没有被内部的pancake所使用,如何把e...

 2 years ago
source link: https://learnblockchain.cn/question/2879
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

5 用自己部署的合约调用pancake购买代币,发现value没有被内部的pancake所使用,如何把eth传入到内部函数(swap)去?

这个是自己的合约:d15fd1ad527a6c9ceb4f05995193605.png

8d5b07c166b3e9a6085fd36341d0d4a.png

用自己的合约调用pancake购买代币,发现value没有被内部的pancake所使用,如何把eth传入到内部函数(swap)去?

最佳答案 5小时前

这个问题其实是如何在 Solidity 中实现,调用合约的时候发送ETH .
只要在调用函数时, 附加{value: 1eth} , 示例代码:

contract contractA {
    function blah(int x, int y) payable {}
}

contract contractB {
    function invokeContractA() { 
        contractA a = contractA(0x1234567891234567891234567891234567891234);
        uint ValueToSend = 1234;
        a.blah{value: ValueToSend}(2, 3);
    }  
}

参考文档, 外部函数调用:
https://learnblockchain.cn/docs/solidity/control-structures.html?highlight=value#external-function-calls

Tiny熊 - 布道者
擅长:智能合约,以太坊 | 采纳率 40% | 回答于 5小时前

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK