Solidity
我在哪裡把主地址放在這個腳本上以將 eth 重定向到主地址?
pragma solidity ^0.4.2; /** * Contract that will forward any incoming Ether to its creator */ contract Forwarder { // Address to which any funds sent to this contract will be forwarded address public destinationAddress; /** * Create the contract, and set the destination address to that of the creator */ function Forwarder() { destinationAddress = msg.sender; } /** * Default function; Gets called when Ether is deposited, and forwards it to the destination address */ function () payable { { if (!destinationAddress.send(msg.value)) throw; } }
例如,我希望將 eth 重定向到的地址是 0x104ea4435b2ed36f36dc403b3638d82ec6a21bb7 但我正在從另一個地址創建契約,我希望契約重定向到上面的地址。我在哪裡把它放在劇本上?
在建構子中,不要將 msg.sender 設置為
destinationAddress
,而是使用您的實際地址:function Forwarder() { destinationAddress = 0x104ea4435b2ed36f36dc403b3638d82ec6a21bb7 }
應該這樣做。
希望這可以幫助