21 lines
652 B
JavaScript
21 lines
652 B
JavaScript
|
|
var getAddress = require('./address').getAddress;
|
|
var convert = require('./convert');
|
|
var keccak256 = require('./keccak256');
|
|
var RLP = require('./rlp');
|
|
|
|
// http://ethereum.stackexchange.com/questions/760/how-is-the-address-of-an-ethereum-contract-computed
|
|
function getContractAddress(transaction) {
|
|
if (!transaction.from) { throw new Error('missing from address'); }
|
|
var nonce = transaction.nonce;
|
|
|
|
return getAddress('0x' + keccak256(RLP.encode([
|
|
getAddress(transaction.from),
|
|
convert.stripZeros(convert.hexlify(nonce, 'nonce'))
|
|
])).substring(26));
|
|
}
|
|
|
|
module.exports = {
|
|
getContractAddress: getContractAddress,
|
|
}
|