I have some questions about Solidity CALL and DELEGATECALL. I have already read some related threads (link), but found no answers to my doubts.

1) Is there any difference in performing a CALL to a function in a Solidity contract by directly calling the function (e.g. funct(arg1) ), or by using addressOfTheContract.call(bytes4(sha3("funct(uint256)")), _n)?

2) Is there any difference in performing a DELEGATECALL to a library function by directly calling the function (e.g. lib.funct(arg1) ), or by using addressOfTheLibraryContract.delegatecall(bytes4(sha3("funct(uint256)")), _n)? Let's assume that in both cases the library is imported with an import statement at the beginning of the contract.

3) Do both CALL and DELEGATECALL generate messages with the same format of a transaction (nonce, to, value, ...), except for the gasPrice and gasLimit fields?

4) Finally, do both CALL and DELEGATECALL take place locally on each node?

2 Answers 2

  1. There is a difference iff you are calling a function within the contract (an "internal" call). Internal function calls are done by jumps and do not require an actual call opcode. The longer form is equivalent to this.funct(arg1)

  2. No, this should be equivalent.

  3. No, CALL and DElEGATECALL are EVM opcodes just like SSTORE or MUL. No transaction is generated, all that happens is that code gets run.

  4. All execution that occurs in a mined transaction happens on every full node on the network. If you simulate the transaction locally, e.g. with a web3 .call (not to be confused with the solidity .call) then it is run only locally


I'm not 100% sure of the first two answers, so wait for some confirmation from others:

  1. No, these should do the same thing.
  2. No, these should do the same thing.
  3. No, calls between contracts don't create transactions at all.
  4. This depends. They run wherever the rest of the code is running. If you make a transaction, the code runs on all nodes. If you use eth_call to make a call to a view/pure function, that executes locally on just the node you're talking to. A CALL or DELEGATECALL that's part of the function execution runs in the same place.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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