3

To access any function of contract, we use :
contractInstance.functionname.sendtransaction() or contractInstance.functionname.call()

Is it possible to call it as :
contractInstance[functionname].sendtransaction() or contractInstance["functionname"].call()?

3

Both contractInstance["functionname"].call() and contractInstance["functionname"].sendTransaction() work.

2
  • Have you implemented it?
    – Aniket
    Sep 1 '16 at 11:36
  • Yes, I tried it on a small project of mine. Sep 1 '16 at 11:51
1

In the documentation you will find all the methods used to call a function from web3.js

// Automatically determines the use of call or sendTransaction based on the method type
myContractInstance.myMethod(param1 [, param2, ...] [, transactionObject] [, defaultBlock] [, callback]);

// Explicitly calling this method
myContractInstance.myMethod.call(param1 [, param2, ...] [, transactionObject] [, defaultBlock] [, callback]);

// Explicitly sending a transaction to this method
myContractInstance.myMethod.sendTransaction(param1 [, param2, ...] [, transactionObject] [, callback]);

// Get the call data, so you can call the contract through some other means
var myCallData = myContractInstance.myMethod.getData(param1 [, param2, ...]);
// myCallData = '0x45ff3ff6000000000004545345345345..'

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.