I am using a local testnet node (Geth 1.7.3) in light mode, and in such case the transaction receipt does not contain the contractAddress when a new contract is deployed.
Therefore I am looking to determine the contract address myself. From what I read it is determined from the nonce and the account: How is the address of an Ethereum contract computed?
I am trying to repliate the logic explained in this post in Python:
def mk_contract_address(sender, nonce):
return sha3(rlp.encode([normalize_address(sender), nonce]))[12:]
In Javascript using web3 1.0.0-beta.26 and RLP package https://github.com/ethereum/wiki/wiki/RLP
My attempt is this:
var mainAccount = "0x5e03df21b770c783b1641bb3b49924e2fed0b3a7"
var Web3 = require("web3")
var web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"))
var RLP = require('rlp');
web3.eth.getTransactionCount(mainAccount, (err, nonce) => {
console.log(web3.utils.sha3(RLP.encode[sender,nonce]))) ;
});
But I do not get the same address once the contract is deployed
Best Answer
I think I finally got it. I am using the example in the original response (in Python):
By running this I get the same result:
address is:
as the nonce0 example above