0

I'm trying to figure out why the web3 contract api does not need to sign the transaction, and only needs a from input to interact with the blockchain

https://web3js.readthedocs.io/en/v1.2.11/web3-eth-contract.html#contract-send

What is going on under the hood?

1 Answer 1

1

The node you're connecting to is actually doing the signing for you (as long as the from address is unlocked), that's why only web3.eth.contract.METHOD needs a from parameter to interact with the blockchain.

See: how come web3 send does not require a private key or signature

4
  • would you know if is there a way to sign it manually with web3? how would other people interact with the method if their address is not unlocked?
    – zcaudate
    Sep 17 at 7:49
  • @zcaudate You'll need to use signTransaction method of web3. Then use the output as argument to sendSignedTransaction. web3js.readthedocs.io/en/v1.8.0/web3-eth.html#signtransaction Sep 17 at 15:21
  • @ShariqHasanKhan How would I do that with a contract method though?
    – zcaudate
    Sep 17 at 15:55
  • the transactionObject (first argument to the signTransaction method) has a data field. Set it to your contract's concerned method. => data: YourContract.methods.ConcernedMethod(arg1, arg2, ...argN).encodeABI() Sep 17 at 16:14

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.