nft-tutorial icon indicating copy to clipboard operation
nft-tutorial copied to clipboard

part 4 / withdrawal task is missing in hardhat

Open fixitornever opened this issue 3 years ago • 5 comments

During Step 4 we add the support of withdrawPayments() to our smart contract however if you want to call that method you need a new hardhat task which is not proposed in the guide.

I suggest something like:

task("withdraw", "*** Transfer the ETH hold by the SC to the account")
.setAction(async function (taskArguments, hre) {
    const account = getAccount();
    const contract = await getContract("NFT", hre);
    const transactionResponse = await contract.withdrawPayments(account.address,
    {
        gasLimit: 500_000,
    });
    console.log(`Transaction Hash: ${transactionResponse.hash}`);
});

This way calling npx hardhat withdraw should withdraw the SC ETH to the account specified with the ACCOUNT_PRIVATE_KEY env variable

fixitornever avatar Feb 11 '22 10:02 fixitornever

This is very helpful thank you. Note you need const { getAccount } = require("./helpers"); at the top of the file also.

Issue https://github.com/ProjectOpenSea/nft-tutorial/issues/4 remains however: When I tried the above task on a Rinkeby contract which had 0.03ETH in it, the withdraw transaction completed successfully but the transaction value on etherscan was 0.00 and nothing was added to my wallet.

Any ideas??

cronoklee avatar Apr 10 '22 09:04 cronoklee

@cronoklee I'm at the same place you are.

...Do we need to specify an amount in the withdrawPayments action?

rangerscience avatar Apr 20 '22 01:04 rangerscience

OZ docs say it's just all funds, but they also say withdrawPayments is deprecated in favor of withdrawPaymentsWithGas.

rangerscience avatar Apr 20 '22 01:04 rangerscience

Adding a call to _asyncTransfer after _safeMint call in the contract seems to solve the issue tho the contract behaves a little differently now. See the pull request for details https://github.com/ProjectOpenSea/nft-tutorial/pull/1

cronoklee avatar Apr 20 '22 08:04 cronoklee

I saw that, and thanks! That meant that the contract address has funds, but my withdraw still doesn't seem to be able to move those funds (although it publishes a transaction).

rangerscience avatar Apr 20 '22 18:04 rangerscience