Solidity
ERC20:津貼不足
呼叫 createVaultItem 函式時出現此錯誤。我的solidity知識還不夠。為什麼我會收到此錯誤?
市場.sol
function createVaultItem(address nftContract,uint256 tokenId,uint256 price) public payable nonReentrant { require(price > 0, "Price cannot be zero"); _itemIds.increment(); require(msg.value == listingFee, "Price cannot be listing fee"); require(mytoken.transferFrom(msg.sender,address(nftContract), listingFee), "Sending Failed"); uint256 itemId = _itemIds.current(); idToVaultItem[itemId] = VaultItem(itemId,nftContract,tokenId,payable(msg.sender),payable(address(0)),price,false); IERC721(nftContract).transferFrom(msg.sender, address(this), tokenId); emit VaultItemCreated(itemId,nftContract,tokenId,msg.sender,address(0),price,false); }
nft.sol
function createNFT(string memory tokenURI) public returns (uint) { _tokenIds.increment(); uint256 newItemId = _tokenIds.current(); _mint(msg.sender, newItemId); _setTokenURI(newItemId, tokenURI); setApprovalForAll(contractAddress, true); return newItemId; }
乙太.js
async function createNFT(url) { let amount = 900000000000; const web3Modal = new Web3Modal() const connection = await web3Modal.connect() const provider = new ethers.providers.Web3Provider(connection) const signer = provider.getSigner() let cri = new ethers.Contract(hhtoken,Token,signer) await cri.approve(hhnft,amount) let contract = new ethers.Contract(nftcontract, NFT, signer) let transaction = await contract.createNFT(url) let tx = await transaction.wait() let event = tx.events[0] let value = event.args[2] let tokenId = value.toNumber() contract = new ethers.Contract(market, Market, signer) await cri.approve(hhmarket,amount) let listingFee = await contract.getListingFee() listingFee = listingFee.toString() const price = ethers.utils.parseUnits(formInput.price, 'ether') transaction = await contract.createVaultItem(nftcontract, tokenId, price, { value: listingFee }) await transaction.wait() router.push('/') }```
您需要增加 ERC20 代幣合約內的限額。
檢查哪個 transferFrom() 失敗,並將“from”的允許值增加到缺少允許的 transferFrom 的“to”
使用您需要的參數嘗試類似 myToken.increaseAllowance() 的方法。
希望這可以幫助