nft-tutorial
nft-tutorial copied to clipboard
Adding _asyncTransfer after _safeMint
Hi!
First of all, thank you for the tutorial! 😄
At part four, I believe that maybe it's missing the deposit of the values after (or before) minting.
I checked at the docs and found the _asyncTransfer
(link) function which stores the value to the Escrow contract.
As I didn't find any example showing up the flow of using PullPayment, I ended up testing it in the tutorial and taking the opportunity to open this PR to know about your opinion and also make it clearer for me.
Many thanks!
Hi,
thanks for posting this PR. I was struggling with exactly the same problem. IMO you are right with your changes and I also applied them to my changes.
Additionally, what I think the tutorial is also missing, is updating the mint.js script so that ether is sent when minting a token.
Here's how I changed the mint. script:
diff --git b/scripts/mint.js a/scripts/mint.js
index 735d165..e1f4e82 100644
--- b/scripts/mint.js
+++ a/scripts/mint.js
@@ -1,12 +1,14 @@
const { task } = require("hardhat/config");
const { getContract } = require("./helpers");
const fetch = require("node-fetch");
+const { ethers } = require("ethers");
task("mint", "Mints from the NFT contract")
.addParam("address", "The address to receive a token")
.setAction(async function (taskArguments, hre) {
const contract = await getContract("NFT", hre);
const transactionResponse = await contract.mintTo(taskArguments.address, {
+ value: ethers.utils.parseEther("0.08"),
gasLimit: 500_000,
});
console.log(`Transaction Hash: ${transactionResponse.hash}`);
you can just pull the token mint price from the contract instead of hard coding a dup in the mint.js:
task("mint", "Mints from the NFT contract")
.addParam("address", "The address to receive a token")
.setAction(async function(taskArguments, hre) {
const contract = await getContract(nftName, hre);
const mintPrice = await contract.MINT_PRICE();
const transactionResponse = await contract.mintTo(taskArguments.address, {
gasLimit: 500000,
value: mintPrice
});
console.log(`Transaction Hash: ${transactionResponse.hash}`);
});