My question; How to get the withdrawPayments, out-of-the-box, no modification to the original OZ source code with JavaScript?
Case, currently I have a smart contract creating ERC721. To mint, I call the following safeMint function:
function safeMint(address to, string memory uri)
public
payable
onlyOwner
returns (uint256)
{
uint256 MINT_PRICE = 5.00 ether;
require(msg.value == MINT_PRICE, "Transaction value did not equal the mint price");
uint256 tokenId = s_tokenIdCounter.current();
s_tokenIdCounter.increment();
_safeMint(to, tokenId);
uri = string(abi.encodePacked(uri, tokenId.toString()));
_setTokenURI(tokenId, uri);
_asyncTransfer(address(this), msg.value);
return tokenId;
}
I use JavaScript to trigger the minting. The amount send is, as you can see, transferred to an Escrow contract using the _asyncTransfer.
To double check, I query the Escrow contract using payments() from the OZ PullPaymentUpgradeable.sol. I can see that ETH is transferred and stored to the Escrow contract using contract.payments(contractAddress) in JavaScript from (again) the PullPaymentUpgradeable.sol.
Query the, in my case Proxy Contract, using JavaScript (const proxyBalance = await ethers.provider.getBalance(contractAddress) results into zero (0).
Guess everything works as might be expected...!?
But! I can't get the withdrawPayments() to work. Nothing gets withdrawn nor send.
So I dived into the Escrow contracts all the way to the withdraw() function in the EscrowUpgradeable.sol, but along the way I get mixed up what the payee should be.
In the PullPaymentUpgradeable.sol it says; @param payee Whose payments will be withdrawn.
In the EscrowUpgradeable.sol it says; @param payee The address whose funds will be withdrawn and transferred to.
The EscrowUpgradeable.sol sounds like a circle reference...? When the Payee address is the address both withdrawn as transferred to. However in the contract code I don't see where the recipient address is entered, only the Payee param is mentioned. I might overlook something here...?
Nonetheless I tried numerous things to try and understand how everything works. And tried the following values when triggering the withdrawPayments(payee) function with the following values:
- parameter payee = Random (but!) valid Recipient Dummy Contractaddress given by Hardhat, no errors, but no ETH is transferred nor withdrawn.
- parameter payee = Contractaddress, but I get an error; 'CurrentContractAddress', the code fails with the error; Address: unable to send value, recipient may have reverted'.
Either way, I can't seem to get the withdrawPayment to work. What am I missing here?
Hope you all can still follow along...
Any thoughts, help and/or solution is very welcome!
Already thanks in advance.
Environment
Hardhat