Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is address(0) in Solidity

Can anyone explain to me what address(0) is in Solidity? I found the following in the docs but it doesn't really make sense to me:

If the target account is the zero-account (the account with the address 0), the transaction creates a new contract. As already mentioned, the address of that contract is not the zero address but an address derived from the sender and its number of transactions sent (the “nonce”). The payload of such a contract creation transaction is taken to be EVM bytecode and executed. The output of this execution is permanently stored as the code of the contract. This means that in order to create a contract, you do not send the actual code of the contract, but in fact code that returns that code.

http://solidity.readthedocs.io/en/develop/introduction-to-smart-contracts.html?highlight=address(0)#index-8

like image 230
pizzarob Avatar asked Jan 12 '18 04:01

pizzarob


People also ask

What is address in Solidity?

In Ethereum and Solidity, an address if of 20 byte value size (160 bits or 40 hex characters). It corresponds to the last 20 bytes of the Keccak-256 hash of the public key. An address is always pre-fixed with 0x as it is represented in hexadecimal format (base 16 notation) (defined explicitly).

Is address a data type in Solidity?

Solidity actually offers two address value types: address and address payable .

What is address in Ethereum?

Ethereum Address means the unique public key cryptocurrency identifier that points to an Ethereum-compatible wallet to which Ether, ONGX or an ERC20 Token or Security Token may be sent or stored. Sample 1. Ethereum Address means a 'wallet' address on the Ethereum Blockchain.


1 Answers

Within an Ethereum transaction, the zero-account is just a special case used to indicate that a new contract is being deployed. It is literally '0x0' set to the to field in the raw transaction.

Every Ethereum transaction, whether it's a transfer between two external accounts, a request to execute contract code, or a request to deploy a new contract, are encoded in the same way. A raw transaction object will look something like this:

transaction = {   nonce: '0x0',    gasLimit: '0x6acfc0', // 7000000   gasPrice: '0x4a817c800', // 20000000000   to: '0x0',   value: '0x0',   data: '0xfffff' }; 

If to is set to something other than '0x0', this request will result in transferring ether to the address (if value is non-zero), and execute the function encoded in the data field. Remember, the address can either be a contract or an external account.

When the to address is the zero-address, a new contract will be created by executing the code in data (this is what is meant by "code that returns the code"). The address of the newly created contract is technically known beforehand as it's based on the address of the sender and it's current nonce. That address becomes the official address of the contract after mining.

For a pretty good read on Ethereum transactions, check out this blog post.

Note: There is also the actual Solidity code statement address(0) which is the initial value of a variable of type address. The documentation you posted, however, is referring to specifically when the to account address in a transaction is set to '0x0'.

like image 120
Adam Kipnis Avatar answered Sep 20 '22 06:09

Adam Kipnis