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.

  • I want to return this address and amount . function transferEther(address payable to, uint amount)public validOwner{ require(amount > 0 && amount <= _balances[address(0)][msg.sender]); Transaction memory transaction; transaction.from = msg.sender; transaction.to = to; transaction.amount = amount; _balances[address(0)][msg.sender] = _balances[address(0)][msg.sender] - amount; to.transfer(amount); tx; emit TransferFunds(_owner, to, amount); } – Nithin Jan 9 at 11:40

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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