![](/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.