[Ethereum] How to read a data sent to the Smart Contract

calldatadappssoliditytransactions

How can I read/ get a data that has ben sent to my smart contract ?

I tested sendTransaction({data: xyz }) and when I tried to get this data from the Smart Contract using msg.data I got NULL this means the data wasn't sent to the SC , any help ? a need the line code of the transaction with a data

Best Answer

Assume you have a solidity function inside your smart contract which accepts data in the form of e.g. an integer called xyz:

function takeData(int xyz)

Now in e.g. geth you can create an instance of that smart contract and call the function by:

contractInstance.takeData.sendTransaction(12345, {from: web3.eth.accounts[0]})

You can find a complete walk-through example which I created for our teaching efforts at Validity Labs on my github: https://github.com/SCBuergel/timeLock-smartContract

Related Topic