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

  • please give example code of both your smart contract and your interfacing method (geth?) to try this. otherwise it is hard to help out specifically.
    – SCBuergel
    May 9 '16 at 12:37
  • token.addAssets.sendTransaction(1,{from: web3.eth.accounts[0], value: web3.toWei(1, 'ether'), data: web3.toHex("0x228aef67c65077f864d9f5e00697578627f3b331")}); this is my transaction
    – sourh
    May 9 '16 at 13:42
  • this is my smart contract function
    – sourh
    May 9 '16 at 13:47
  • function addAssets(int amount) returns (bytes) {ad=msg.data; if (msg.sender == 0xd1b4b395a0f9deff0275c3cca2eeb9539af365e2) balanceOf[msg.sender]=balanceOf[msg.sender]+amount; else throw; return ad; }
    – sourh
    May 9 '16 at 13:47

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

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.