2

Using Truffle and the CryptoZombies example code, when I type ZombieFactory.deployed() the contract is shown with all of its functions. For example,

createRandomZombie:
  { [Function: bound ]
    request: [Function: bound ],
    call: [Function: bound ],
    sendTransaction: [Function: bound ],
    estimateGas: [Function: bound ],
    getData: [Function: bound ],
    string: [Circular] },
 allEvents: [Function: bound ],
 NewZombie: { [Function: bound ] 'uint256,string,uint256': [Function: bound ] },
 OwnershipTransferred: { [Function: bound ] 'address,address': [Function: bound ] } },

What does [Function: bound] mean? Why are request and call shown? They are not separate functions that are in the Solidity file.

1

Truffle for every contract function it creates several "shortcuts":

  • function() will create a transaction and wait for it to be mined,
  • function.sendTransaction() will create a transaction and return immediately the txhash,
  • function.call() will make a call overriding the abi definition (will not modify the contract state),
  • function.estimateGas() will estimate the execution gas,
  • function.request() return the JSON-RPC formatted command.
  • what does it mean for a call to override abi definition? would not the call have to be compatible with the function definition? – Jeff Apr 23 '18 at 14:53
  • The abi specifies for each function if it is constant or not. Truffle will map function() to the default operation, ie constant function will make a call, and non constant function will make a transaction. Using .sendTransaction() or .call() you can override the default behavior. – Ismael Apr 23 '18 at 15:28
  • Please point me to what a "constant function" is in the case here (I think) of Solidity is. Also, does an abi not do more than specify constant or not? – Jeff Apr 24 '18 at 0:56
  • A constant function is a function that doesn't modify the contract storage, for example querying a token balance. Non constant functions are the ones that modify the contract storage, for example a transfer of tokens because it has to adjust the balances of sender and recipient. The solidity abi is complex, you can look at the latest specification solidity.readthedocs.io/en/v0.4.23/abi-spec.html. – Ismael Apr 24 '18 at 2:25

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.