Solidity
web3中的備份功能
我在這裡找到瞭如何製作可升級契約的答案
如何在 web3 上使用備份函式從 currentVersion 呼叫函式?
contract Relay { address public currentVersion; address public owner; function Relay(address initAddr){ currentVersion = initAddr; owner = msg.sender; } function update(address newAddress){ if(msg.sender != owner) throw; currentVersion = newAddress; } function(){ if(!currentVersion.delegatecall(msg.data)) throw; } }
您可以使用sendTransaction函式執行此操作,如下所示:
web3.eth.sendTransaction({ from: sendingAccount, to: contract.address, data: yourData, // optional, if you want to pass data or specify another function to be called by delegateCall you do that here gas: requiredGas, // technically optional, but you almost certainly need more than the default 21k gas value: value //optional, if you want to pay the contract Ether });
您可能不再需要它,但您可以將中繼地址重新輸入到實例合約:
contract Instance{ function doSomething(){ ... } }
然後如果 Relay.deployed() 位於地址 0x12345678,請執行以下操作:
in = Instance.at('0x12345678') in.then(function(i){ i.doSomething(); })