-1

I am trying to return a value of a public state variable highestBid in solidity through JavaScript, what is a possible way to save the value from the call to a variable? Currently I am getting: undefined.

TS:

    async getHighestBid() {
       this.smartAuction.setProvider(this.provider);
       let result = await this.smartAuction.deployed().
                         then(function(contract: { highestBid: { call: () => Promise<any>; }; })  {contract.highestBid.call().
                         then(function(v) {return v})});
       console.log(result);
  }

Sol:

contract SmartAuction {
    address payable public beneficiary;
    uint public auctionEnd;

    address public highestBidder;
    uint public highestBid;

    mapping(address => uint) private pendingReturns;

    bool private ended;
...
}
Yilmaz
  • 35,338
  • 10
  • 157
  • 202
dovexz12323
  • 197
  • 5

1 Answers1

1

if console.log(result) logs correctly, you have to return result in the function so when you call the function, it will give you the return value.

 return result

in javascript if you do not return anything in a function, and if you call the function, it will execute the function body but it will return you undefined

Yilmaz
  • 35,338
  • 10
  • 157
  • 202