2

Basic question:

If I do myContract = eth.contract([abi goes here]), then I get do a:

var contract = myContract.new(
  /* args */,
  {
    from: eth.accounts[0],
    data: compiledContract,
    gas: 1000000
  }
)

I receive back:

fullhash=0x830e6922af1008... 
contract=0xA94C943B7b...

What is this contract hash value actually used for?

3 Answers 3

4
+50

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

https://medium.com/@codetractio/inside-an-ethereum-transaction-fa94ffca912f

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

2

That is basically contract address which will be used once you would like to interact with the deployed contract. To interact with the already deployed contract you need its ABI and address.

The same contract can be deployed multiple times and thus can have same ABI but each time contract address will be different. So contract address is unique property of contract.

1
  • 2
    The contact address is not something that is created once the contract is deployed. It is created once you send a transaction for creating a contract. Are you sure, this is not the contract address? You can deploy your contract on testnet and compare this contract address with the address once the contract is successfully deployed. I think they must be same. Commented Feb 4, 2018 at 19:52
2

Contract address will generated at the time of contract submitted to network. Contract creation is also a transaction, so eth will generate transaction hash. In ethereum, contract is unmanageable account.

Ethereum contract address generation algo is:

creator (sender) and how many transactions the creator has sent (nonce). The sender and nonce are RLP encoded and then hashed with Keccak-256.

Please find below link for more details: http://martin.swende.se/blog/Ethereum_quirks_and_vulns.html

When you deployed a contract in geth, eth will create contract object. If you want to access deployed contract you need some identity. Here contract identity is contract address. And full hash is transaction hash. ABI is JSON file for just loading methods that deployed contract contain. So that using web3js or any other client to call those methods. bin is actuval contract instructions or opcodes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.