0 votes
1 view
in Blockchain by (11.8k 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 (27.7k points)

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.
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...