0 votes
1 view
in Blockchain by (4.1k points)

With this below solidity code I have tried to send ether to ethereum wallet address 0x1 via smart contract and it becomes failed. But, when I try to send ether to address 0x1 directly from my wallet it becomes success.

pragma solidity ^0.4.24;

contract Transfer {

    constructor () public payable {
        // Deploy contract with 1000 wei for testing purpose
        require(msg.value == 1000);
    }

    function done() public {
        address(0).transfer(1); // Transaction success
    }

    function fail() public {
        address(1).transfer(1); // Transaction failed
    }

    function send(address account) public {
        account.transfer(1); // Transaction success (except 0x1)
    }

}
 

Why we can't send ether to address 0x1 via contracts ?

REFERENCE:

Sending ether directly from my wallet is success https://ropsten.etherscan.io/tx/0x1fdc3a9d03e23b0838c23b00ff99739b775bf4dd7b5b7f2fa38043056f731cdc

done() function is success https://ropsten.etherscan.io/tx/0xd319c40fcf50bd8188ae039ce9d41830ab795e0f92d611b16efde0bfa1ee82cd

fail() function is failed https://ropsten.etherscan.io/tx/0x0c98eafa0e608cfa66777f1c77267ce9bdf81c6476bdefe2a7615158d17b59ad

1 Answer

0 votes
by (14.4k points)

You are getting these issues because you have ignored the fact that Ethereum has certain pre-compiled contracts. One of those contracts is the ecrecover contract.

And the fail() function is failing because it is out of gas. The fallback execution of ecrecover requires more than 2300 gas and it must be forwarded by the transfer method. For this reason, the function is not executing. 

And finally, you must know that the 0*0 address is not a special contract. So, it could be resolved with a regular transfer call.

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...