0

I have some basic questions about web3. Is it common to send transactions to the smart contract address when calling methods in the smart contract or should I send them to another wallet?

When executing this line of code, the contract address is automatically set as the recipient by the contract instance, right? Is the transaction automatically signed when this line is executed?

Thank you!

return await registerContractInstance.methods.addUserAddress("test").send({from: senderAddress});
1

Is it common to send transactions to the smart contract address when calling methods...

Yes, a method in a smart contract is only called when it receives a transaction (or a message passed from another contract, sometimes called an "internal transaction").

When executing this line of code, the contract address is automatically set as the recipient by the contract instance, right?

Yes.

Is the transaction automatically signed when this line is executed?

Yes.

  • Is it then also possible to specify another recipient by calling a Smart Contract method for data transfer? If so, when would this make sense? – P_F Jan 10 at 20:32
  • I'm not sure what you're asking. The contract can do whatever you program it to do, and you can pass whatever arguments to it you want. – smarx Jan 10 at 20:33
  • In the code line above, a transaction is created in which the recipient address is the Smart Contract. Could I also send data to this Smart Contract but add a different recipient address? For example from a completely random wallet? If so, when would this make sense? – P_F Jan 10 at 20:41
  • 1
    "Could I also send data to this Smart Contract but add a different recipient address?" I'm not sure what you mean. If the to address of the transaction is not the smart contract, then the smart contract won't run. Then you say "from a completely random wallet." No you're talking about the from address? And could you confirm that "wallet" is another word for "address" for you? (Sometimes it means software that you use to interact with the blockchain, e.g. MyEtherWallet.) – smarx Jan 10 at 20:43
  • Yes exactly, so if I sent the transaction to a different address instead of the Smart Contract address. For example, by specifying the other address in the "To" field. Okay, then this means that the Smart Contract will not be executed? – P_F Jan 10 at 20:55
0

You would want to send a transaction to the smart contract. In the tx object you would have the to address (the contract) other things that are constant in regular transactions (gas, nonce etc) and then the data would contain the actions. So the hash of the functions and the parameters to send through it (taken from the abi)

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.