0

Does someone know what the .encodeABI() means on this the below line of code please?:

const data = electionContract.methods.vote(1).encodeABI()

Thank you

Take care

Pierre

3
  • The encoded ABI of the transaction denoted by electionContract.methods.vote(1). Aug 20, 2020 at 21:32
  • That's what is passed to the data parameter when signing a transaction to execute the "vote" function with the input parameter "1".
    – clement
    Aug 21, 2020 at 10:26
  • thank you very much goodvibration and clement
    – Pierre
    Aug 22, 2020 at 13:09

1 Answer 1

1

Encodes the ABI for that method. The resulting hex string is 32-bit function signature hash plus the passed parameters in Solidity tightly packed format. This can be used to send a transaction, call a method, or pass it into another smart contract’s method as arguments. Set the data field on web3.eth.sendTransaction options as the encodeABI() result and it is the same as calling the contract method with contract.myMethod.send().

Some use cases for encodeABI() include: preparing a smart contract transaction for a multisignature wallet, working with offline wallets and cold storage and creating transaction payload for complex smart contract proxy calls.

REF: web3js-documentation-->methods-mymethod-encodeabi

To learn more: what-exactly-does-encodeabi-from-web3

0

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