Solidity
在呼叫 _addr.call(abi.encodeWithSignature(…)) 之前設置變數不會改變
我在我的合約函式中呼叫了一個名為“getExpectedReturn”的 1icnh 智能合約函式。當我在呼叫之前設置一個變數(名為 v1)時,該變數不會改變,但如果我在呼叫之後設置一個變數(名為 v2),它會起作用。我不知道為什麼會這樣。以下是重現該問題的簡單契約:
pragma solidity ^0.6.6; contract A { address internal constant ONE_INCH_ADDRESS = 0xC586BeF4a0992C495Cf22e1aeEE4E446CECDee0E; uint256 public v1 = 1; uint256 public v2 = 2; event Ev1( uint256 v1, uint256 v2); function A1 () public { v1 = 11; /*this does not work*/ ONE_INCH_ADDRESS.call(abi.encodeWithSignature( "getExpectedReturn(address,address,uint256,uint256,uint256)", 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE, 0x6B175474E89094C44Da98b954EedeAC495271d0F, 1000000000000000000, 100, 0)); v2 = 22; /* this works*/ emit Ev1(v1, v2); /* here v1 is 1 but should be 11 ! and v2 is 22*/ } }
函式A的執行日誌附在下面:
[ { "from": "0x69A5e5e86c72aE3D57bBD25A38f63bc527176228", "topic": "0x9aa0a5ee181172acba4a8b7e3c24db463f4c218ff10a6ea1777f43817d257414", "event": "Ev1", "args": { "0": "1", "1": "22", "v1": "1", "v2": "22", "length": 2 } } ]
歡迎任何建議。
PS1:合約部署在 remix 的分叉主網上。(使用的地址在乙太坊主網上,ETH:0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE,DAI:0x6B175474E89094C44Da98b954EedeAC495271d0F)
似乎是一個 ganache-cli 錯誤。
這是您在主網上的交易,事件看起來很好。