Why we can't send ether to ethereum address 0x1 via smart contracts
Why we can't send ether to ethereum address 0x1 via smart contracts
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
2 Answers
2
You have accidentally stumbled upon one of ethereum's lesser known "features". The chain actually has a few precompiled contracts (Appendix E in the yellowpaper), one of which lives at 0x0000000000000000000000000000000000000001
(the ecrecover
contract).
0x0000000000000000000000000000000000000001
ecrecover
Your fail()
function fails with out of gas due to the fact that the ecrecover
contract's fallback execution will require more than the 2300 gas
forwarded by the transfer
method.
fail()
ecrecover
2300 gas
transfer
The 0x0
address is not a special contract, so a regular transfer call works just fine, as it would with any other address.
0x0
After researching about ethereum pre-compiled contracts I have written this below solidity code to send ether to 0x1 address via smart contract and it's working.
pragma solidity ^0.4.24;
contract Learning
constructor () public payable
// Deploy contract with 1000 wei for testing purpose
require(msg.value == 1000);
function test() public returns (bool)
// Set minimum gas limit as 700 to send ether to 0x1
transfer(0x0000000000000000000000000000000000000001, 1, 700);
return true;
function transfer(address _account, uint _wei, uint _gas) private
require(_account.call.value(_wei).gas(_gas)());
For testing, just deploy contract with 1000 wei and execute test()
function. It's working :)
test()
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.