[英]How to retrieve a value of a public state variable from Solidity smart contract in TypeScript?
我正在嘗試通過 JavaScript 以 solidity 返回公共狀態變量highestBid
的值,將調用中的值保存到變量的可能方法是什么? 目前我得到: 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);
}
索爾:
contract SmartAuction {
address payable public beneficiary;
uint public auctionEnd;
address public highestBidder;
uint public highestBid;
mapping(address => uint) private pendingReturns;
bool private ended;
...
}
如果console.log(result)
記錄正確,你必須在函數中返回result
,所以當你調用函數時,它會給你return
值。
return result
在javascript中,如果你不在函數中返回任何東西,如果你調用函數,它會執行函數體,但它會返回undefined
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.