Web3 1.0: What does `web3.eth.call(tx)` return for a contract creation?

0 votes

When using web3.eth.call(tx) for a method call, the return value is a byte string that can be decoded by using web3.eth.abi.decodeParameters(abi.outputs, bytestring). But for a contract creation transaction, we don't have abi.outputs.

Running some test code I can see that web3 is returning some bytestring:

The transaction:

{ from: '0x0838ab6597248e7fb1c11e582eaf88550cce5fb6',
        to: undefined,
        data: '608060405234801561001057600080fd5b506040516020806101ec8339810160409081529051336000908152602081905291909120556101a8806100446000396000f30060806040526004361061004b5763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166370a082318114610050578063a9059cbb14610090575b600080fd5b34801561005c57600080fd5b5061007e73ffffffffffffffffffffffffffffffffffffffff600435166100d5565b60408051918252519081900360200190f35b34801561009c57600080fd5b506100c173ffffffffffffffffffffffffffffffffffffffff600435166024356100e7565b604080519115158252519081900360200190f35b60006020819052908152604090205481565b3360009081526020819052604081205482111561010357600080fd5b336000818152602081815260408083208054879003905573ffffffffffffffffffffffffffffffffffffffff871680845292819020805487019055805186815290519293927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929181900390910190a3506001929150505600a165627a7a72305820329f975019ded1c786284c0fa829c72d65b4e50562f4d0d31707e0140d200c0300295ded32980000000000000000000000000000000000000000000000000000000000000032',
        value: '0x0',
        gas: '0x33274' }

The returned bytestring:


What information is encoded in this bytestring? And can I recover the to-be-deployed contract address?

Sep 17, 2018 in Blockchain by slayer
• 29,040 points

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

The returned bytestring is the deployedBytecode of the contract, i.e. it's what is returned by web3.eth.getCode(contractAddress).

To get the to-be-deployed contract address use the following code:

const rlp = require('rlp');
const keccak = require('keccak');

const sender = '0x123...' // the address that sends the contract creation tx
const nonce = web3.eth.getTransactionCount(sender)
const contractAddress = web3.utils.toChecksumAddress(keccak('keccak256').update(rlp.encode([sender, nonce])).digest('hex').substring(24))
answered Sep 17, 2018 by digger
• 27,620 points

Related Questions In Blockchain

0 votes
1 answer

Çannot implement web3.eth.subscribe on Web3 version 1.0.0-beta.27

As the error suggests, pub/sub is not ...READ MORE

answered Jun 19, 2018 in Blockchain by Perry
• 16,450 points

edited Jun 19, 2018 by Perry 221 views
0 votes
1 answer

Can a hacker change data of a smart sontract without call contract function?

A contract's content cannot be changed internally. ...READ MORE

answered Apr 7, 2018 in Blockchain by Shashank
• 10,330 points
0 votes
1 answer

What could be the best term to use for the collection of contracts in a .sol file?

module - don't think so. Because module ...READ MORE

answered Jun 1, 2018 in Blockchain by Shashank
• 10,330 points
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
+1 vote
3 answers

Removing double quotes from a string from JSON response in PHP

Just remove the json_encode call, and it should work: $resp ...READ MORE

answered Sep 12, 2018 in Blockchain by digger
• 27,620 points
0 votes
1 answer
+1 vote
3 answers

What is the pattern for handling throw on a Solidity contract in tests

In my opinion the cleanest way is: it("should ...READ MORE

answered Sep 25, 2018 in Blockchain by Lupin
0 votes
1 answer

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.