0

How to return the struct data

struct Transaction  {
  address from;
  address payable to;
  uint amount;
}

I am returning like this

function transactionDetails() external view 
        returns(address, address, uint) {
    address from;
    address to;
    uint amount;
    return (from, to, amount);
}

But it showing

0: address: 0x0000000000000000000000000000000000000000
1: address: 0x0000000000000000000000000000000000000000
2: uint256: 0
1

Declare the structure as a public variable. As we know public variable in solidity is constant read method.

struct Transaction  {
  address from;
  address payable to;
  uint amount;
}

Transaction public tx;

Now call tx() method to get the value of the structure's elements.

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.