1

I am a newbie to the blockchain world. I have written contract code in solidity and tested in remix. I am able to get the list values from the struct, but I am confused on how I can get a single record from the blockchain.

How could the input data which I previously set be retrieved using solidity?

Can anyone help me, please?

1
  • 2
    You should share the code you have written, show us the output you are getting, and then tell us the output you want/expect instead. Commented Nov 21, 2018 at 9:28

1 Answer 1

0

You should do a getter function for that. If the data is inside a struct you can only retrive all of them, but you could do a getter for it

struct MyData {
    uint a;
    uint b;
}

MyData public myData;

function setData(uint a, uint b) external {
    myData.a = a;
    myData.b = b;
}

function getData() external view returns(uint a, uint b) {
    a = myData.a;
    b = myData.b;
}
4
  • 1
    That is correct, but since myData is declared as public, it already has a getter, if you call getData() and myData() and you'll get the same result. Commented Nov 21, 2018 at 10:01
  • @Ricardo Guilherme Schmidt On what basis that you are getting a,b values .There is any way that to get the values by passing id or transcation id. to get a single record Commented Nov 21, 2018 at 10:44
  • What exactly do you mean by a single record? Commented Nov 21, 2018 at 12:41
  • Yes, i mean single record @nikos fotiadis Commented Nov 22, 2018 at 6:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.