3

The Yellow Paper Appendix H defines the CREATE and CALL opcodes. For CALL:

the operand order is: gas, to, value, in offset, in size, out offset, out size.

By setting the second operand (the "to") as zero, can the CALL opcode be used to create a contract?

If that's possible, what would the differences between using CREATE and CALL be? Are there any cases where it would be better (for example cheaper gas) to use the CALL opcode to create a contract?

2

By setting the second operand (the "to") as zero, can the CALL opcode be used to create a contract?

No it cannot. The zero address is not special. Just like any other non-contract account, it has no code to execute when it receives a message via the CALL opcode.

Another intuitive way to think about this is that each opcode has its own gas cost, so this would be a funny hack for avoiding the cost of a CREATE operation.

1

I am still new to this but my understanding is that it is not possible. Call is to be used only when the request does not modify the state of the blockchain (typically only reading fields or calling constant marked functions.

Creating a new contract instance is obviously modifying the blockchain data as it has to be integrated into the block before the address can be returned.

In my experimentations (so far) I only use the following patterns and it is sufficient:

  • Creating contract instance: asynchronous call (using sendTransaction). Completion is managed through the callback, called once with the Tx hash and a second time with the contract address.
  • Reading contract data: synchronous call to the local node via the call methodology.
  • Updating data: asynchronous call (using sendTransaction) with methods that do not return values. Call returns synchronously (or eventually async.) the Tx hash that can then be monitored for completion via the getTransactionReceipt (using the eth.filter('latest') that tells when the next block has been mined)
  • Receiving info asynchronously: Use of event in the contract. Monitor the reception via eth.filter( options, callback ).
  • Catching up with events after a disconnected period: use eth.filter({fromBlock: xyz, toBlock: eth.currentBlock, ...}).get()

All this is explained (in synthetic form) in the API https://github.com/ethereum/wiki/wiki/JavaScript-API

  • The EVM CALL opcode is quite unrelated to the eth_call interface (which eventually might make way for eth_simulateTransaction) – eth Feb 23 '17 at 21:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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