繁体   English   中英

ERC20代币合约的批准function问题

[英]Problem with the approve function of ERC20 token contract

因此,每当我尝试使用 ERC20 代币合约的批准 function 来批准我的智能合约时,所有者和支出者的设置都是相同的。

function getValues(address _token) external {
       
        MyToken token = MyToken(0xd9145CCE52D386f254917e481eB44e9943F39138);
        token.approve(address(this),10);
                   
}
function transfer(address _token) external {
      MyToken token = MyToken(0xd9145CCE52D386f254917e481eB44e9943F39138);
    token.transferFrom(msg.sender,address(this),10);
}

The output to the code is coming something like this [ { "from": "0xd9145CCE52D386f254917e481eB44e9943F39138", "topic": "0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925", "event": "Approval", "args": { "0": "0xf8e81D47203A594245E36C48e151709F0C19fBe8", " 1": "0xf8e81D47203A594245E36C48e151709F0C19fBe8", "2": "10", "owner": "0xf8e81D47203A594245E36C48e151709F0C19fBe8", "spender": "0xf8e81D47203A594245E36C48e151709F0C19fBe8", "value": "10" } } ]

在智能合约中调用approve使合约成为对approval function的调用的msg.sender,如果你想使用approval,你在get values中所做的是批准合约移动合约已经拥有的代币移动用户令牌的合约应由用户进行

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM