war*_*que 0 javascript asynchronous async-await ethereum web3-donotuse
更新:下面是我要检查令牌是否存在的代码。如果是,那么我将检查钱包所有者是否是令牌所有者。现在的问题是它没有检查第二个函数“ contract.methods.ownerOf(tokenId).call(function(err,res)”),因此最终结果不是正确的结果。
async function doesTokenIdExist(tokenId, contract, walletAddress) {
var tokenExists = false;
await contract.methods.exists(tokenId).call(async function (err, res) {
if (res) {
await contract.methods.ownerOf(tokenId).call(function (err, res) {
if (!err) {
tokenAddress = res.toLowerCase();
walletAddress = walletAddress.toLowerCase();
if (tokenAddress.localeCompare(walletAddress) == 0){
tokenExists = true;
} else {
tokenExists = false;
}
} else {
tokenExists = false;
}
});
} else {
tokenExists = false;
}
});
return tokenExists;
}
Run Code Online (Sandbox Code Playgroud)
改变这个
await contract.methods.exists(tokenId).call(function (err, res) {
Run Code Online (Sandbox Code Playgroud)
为此,
await contract.methods.exists(tokenId).call(async function (err, res) {
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
40 次 |
| 最近记录: |