This might help
Effectively the creation of a contract results in a full hash involving the sender address and nonce; the contract
address is then taken as 0x
followed by the last 20 bytes of this hash. This is known immediately upon contract creation as it only depends upon the sender address and nonce, and will be included in the blockchain once the transaction has been mined successfully.
by omitting the to field, a contract will be created. But how is the
contract’s address determined? Take for example this transaction
console.log(web3.eth.getTransactionReceipt('0x77a4f46ff7bf8c084c34293fd654c60e107df42c5bcd2666f75c0b47a9352be5').contractAddress);
//0x950041c1599529a9f64cf2be59ffb86072f00111
The contract address is the last 160 bit hash of the sender address
and its nonce can be determined beforehand. For this transaction, the
sender and nonce can be found by
var contractTx = web3.eth.getTransaction('0x77a4f46ff7bf8c084c34293fd654c60e107df42c5bcd2666f75c0b47a9352be5');
console.log(contractTx.from);
//0x84f9d8b0e74a7060e20b025c1ea63c2b171bae6f
console.log(contractTx.nonce);
//0
Thus the contract address is
console.log('0x' + util.bufferToHex(util.rlphash(['0x84f9d8b0e74a7060e20b025c1ea63c2b171bae6f', 0])).slice(26));
//0x950041c1599529a9f64cf2be59ffb86072f00111
This means that for a given sender address we can know what the future addresses will be for any contracts it deploys, as long as it deploys them in the right order (i..e with the right nonce). There are some interesting possibilities this enables, such as sending ether to an empty address to pre-fund a contract which is deployed later in time - just be careful not to miss the nonce to deploy the contract to that specific address or there'd be no chance of getting it back - see 'hiding in plain sight' here for more info