I just started learning about interacting with smart contract deployed on Ethereum blockchain and I've come across these two methods to interact with non-view functions in the contract.

  1. MyContract.methods.Mymethod().send({from: ..some address}) and
  2. web3.eth.sendSignedTransaction(...) and specify the hash of the contract's method call in the data field of the transaction.

It seems that these two ways can both interact with the states and methods in the smart contract. So what's the difference? Can I use 1. instead of 2. or 2. instead of 1.? or is there any disadvantage in using either methods? Thanks in advance.

Another related question is that the 2nd way needs private key to sign the tx but the 1st doesn't. If both can interact with the state, then what's the point of signing tx with private key? Correct me if I understand wrong, thanks.


There should be no difference.

The MyContract.methods.Mymethod().send({from: ..some address}) is a wrapper over sendTransaction (or sendSignedTransaction).

For the 1. to work it has to be connected to a wallet provider that will sign the transaction. For example @truffle/hdwallet-provider will sign the transaction with the private key or mnemonic provided.


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.