0

I am newbie in Solidity. I've read that the address for an Ethereum contract is deterministically computed from the address of its creator (sender) and how many transactions the creator has sent (nonce). The sender and nonce are RLP encoded and then hashed with Keccak-256. I'm trying to make a script in web3.js or native JS, but the hash I'm getting from my script is not the same as in Solidity. Is there any method in web3js to compute smart contract address?

web3.js code:

web3.sha3(web3.padLeft(('1','0x6ac7ea33f8831ea9dcc53393aaa88b25a785dbf0').toString(16),64,0),{encoding: 'hex'})

// gives "0x17ad8f6cbdc29e25e772f16472c10edbc451a0a98ae4a8a0486ac6a7b1678a9e"

Alos this not working:

var nonce=web3.toHex(1);
var adr='0x6ac7ea33f8831ea9dcc53393aaa88b25a785dbf0';
web3.sha3(nonce,adr, {encoding: 'hex'});

//this gives 0x8a07523229fdc48491a5e56c76620ba40639eb940e6a2fbdf62b2799b4c86643