![](/img/trans.png)
[英]MintTo contract from web3 gives error - ERC721: transfer to non ERC721Receiver implementer
[英]retrieving web3 contract.ownerOf NFT ERC721
我正在玩 web3 和前端,试图从以太坊区块链中读取一些东西。 我想做的是验证 NFT (erc721) 的所有者。
我在这里使用了这段代码,它使我能够检查链接到连接的钱包地址的某个 ERC20 的余额
function getERC20TokenBalance(tokenAddress, walletAddress, callback) {
let minABI = [
// balanceOf
{
"constant":true,
"inputs":[{"name":"_owner","type":"address"}],
"name":"balanceOf",
"outputs":[{"name":"balance","type":"uint256"}],
"type":"function"
},
// decimals
{
"constant":true,
"inputs":[],
"name":"decimals",
"outputs":[{"name":"","type":"uint8"}],
"type":"function"
}
];
let contract = web3.eth.contract(minABI).at(tokenAddress);
contract.balanceOf(walletAddress, (error, balance) => {
// ERC20トークンの decimals を取得
contract.decimals((error, decimals) => {
balance = balance.div(10**decimals);
console.log(balance.toString());
callback(balance);
});
});
}
setInterval(function() {
let tokenAddress = '0x50f5474724e0ee42d9a4e711ccfb275809fd6d4a';
let walletAddress = web3.eth.accounts[0];
if(tokenAddress != "" && walletAddress != "") {
getERC20TokenBalance(tokenAddress, walletAddress, (balance) => {
document.getElementById('text-bal').innerText = balance.toFixed(3);
});
};
}, 100);
现在我想验证某个 NFT,我使用了 0x50f5474724e0ee42d9a4e711ccfb275809fd6d4a(SANDBOX 土地合同)。 使用 balanceOf,它确实显示该地址中有 LAND NFT,但我想检查 tokenID,将其更改为
let contract = web3.eth.contract(minABI).at(tokenAddress);
contract.ownerOf('18429');
它什么也没返回,你们能指出我正确的方向吗:)?
代币不在合约的余额上,它们在合约里面。 根据erc721 - 你必须调用合约的balanceOf
方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.