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
}
Это должно сработать.
Надеюсь это поможет