Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Blockchain by (12.7k points)

In the IBM Example of Ethereum smart contract, there is this following code:

personal.unlockAccount(thesponsor,"password"); 

ss.pledge("Good luck with the run!", {from: thesponsor, value: 10000000, gas: 3000000}); 

However, the pledge function is not a payable modifier and it only accepts one argument as the parameter:

function pledge(bytes32 _message) {

  if (msg.value == 0 || complete || refunded) throw;

  pledges[numPledges] = Pledge(msg.value, msg.sender, _message);

  numPledges++;

}

So, is solidity automatically seeing {from: thesponsor, value: 10000000, gas: 3000000} as a msg object that transfers ethers from my account?

I just found this feature a bit weird. What if I wrote a JSON object that happens to contain the keywords "from" and "value", would I accidentally transfer any funds?

1 Answer

0 votes
by (29.5k points)
edited by

Let's address your questions one by one

  • First, you are correct in your observation that the {from: thesponsor, value: 10000000, gas: 3000000} is interpreted as a transactionObject. This is because any transaction on Ethereum that causes a state change requires a transactionObject such as the one above to allow your code to be executed on the blockchain.
  •  Functions in Ethereum if they make state changes will take in the parameters for the function first, followed by the transactionObject behind. You should simply make sure that you don't write the transactionObject accidentally as it will be interpreted as a transaction.
Give yourself time to explore the Blockchain field properly. Enroll in Blockchain Online Training now.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...