我想做一个表格,列出用户钱包和其在币安智能链上某个币种的余额 钱包地址全部在 data1.json 中,余额需要实时从链上获取
<link href="https://unpkg.com/[email protected]/dist/bootstrap-table.min.css" rel="stylesheet">
<script src="https://unpkg.com/[email protected]/dist/bootstrap-table.min.js"></script>
<table
id="table"
data-toggle="table"
data-height="460"
data-url="json/data1.json">
<thead>
<tr>
<th data-field="owner" data-formatter="ownerFormatter">Item Name</th>
<th data-field="balance" data-formatter="priceFormatter">Item Price</th>
</tr>
</thead>
</table>
<script>
function ownerFormatter(value, row) {
return '<span>'+value+'</span>';
}
async function balanceFormatter(value, row) {
let wallet_address = row['owner'];
let sss_balance = 0;
//window.abi_json 在其他地方定义
let MyContract = new web3.eth.Contract(window.abi_json,'0xC3028FbC1742a16A5D69dE1B334cbce28f5d7EB3');
//根据 WEB3 文档在线读取某币种余额 ,console.log(sss_balance)是可以正常打印余额的
sss_balance = await MyContract.methods.balanceOf(wallet_address).call();
//返回余额
return sss_balance;
}
</script>
上面的 balanceFormatter 肯定是有错误的. async 返回的是一个 Promise 对象,但是删除 async 和内部的 await 也不行.求助大神....太菜了我
1
msg7086 2022-04-17 06:22:01 +08:00
priceFormatter ?
balanceFormatter ? |