我有一个ERC20合同,在ERC721合同中调用BalanceOf;
在我的ERC20合同中;
import "./NFT.sol";
contract ERC20 {
NFT public nft;
constructor (NFT _nftAddress) public {
nft = _nftAddress;
}
function getNFTBalance(address _nftOwner) public view returns (uint256 result){
nft.balanceOf(_nftOwner);
return result;
}我用的是来自OpenZeppelin的OpenZeppelin
我的NFT合同进口NFT 21溶胶
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";在the 721中,BalanceOf函数;
function balanceOf(address owner) public view override returns (uint256) {
require(owner != address(0), "ERC721: balance query for the zero address");
return _holderTokens[owner].length();
}这就是我如何在2_deploy_contracts.js中部署时传递契约地址的方式。
module.exports = async function(deployer) {
// deploying the ERC20 Token
const accounts = await web3.eth.getAccounts();
await deployer.deploy(Token);
// deploying the NFT
const NFT_NAME = "ID Exclusivity Token";
const NFT_SYMBOL = "IDET";
const NFT_API = "https://example.com/nft/api/token/"
await deployer.deploy(NFT, NFT_NAME, NFT_SYMBOL, NFT_API)
.then( async () => {
nftContractAddress = NFT.address;
console.log('NFT ADDRESS : ',nftContractAddress)
const feeAccount = accounts[0];
const feePercent = 10;
//Deploying Exchange with the NFT address
await deployer.deploy(Exchange, nftContractAddress, feeAccount, feePercent);
})
};我可以用控制台日志确认地址是正确的。
部署完毕后,在松露控制台中:
nft = await NFT.deployed()
await nft.mint("0x851ffbF315d9d32E8DBE75b10B1E0b8C030320cf")
exchange = await Exchange.deployed()
await exchange.getNFTBalance("0x851ffbF315d9d32E8DBE75b10B1E0b8C030320cf") // return 0
await nft.balanceOf("0x851ffbF315d9d32E8DBE75b10B1E0b8C030320cf") // return 1发布于 2020-10-09 18:52:17
我返回了一个默认情况下为0的结果。
将功能改为;
function getNFTBalance(address _owner) public view returns (uint256){
return nft.balanceOf(_owner);
}现在得到正确的平衡
https://ethereum.stackexchange.com/questions/88195
复制相似问题