What's wrong with this withdraw function? It keeps reverting with the error below. I have tried different methods to withdraw (see commented lines) but the error is the same.
- I'm sure I'm parsing the correct contract address. I have copy pasted it from
thirdweb dashboard
myself.
For the whole code, check out My Repo
Error
Error occurred while withdrawing funds Error:
╔═══════════════════╗
║ TRANSACTION ERROR ║
╚═══════════════════╝
Reason: missing revert data in call exception; Transaction reverted without a reason string
╔═════════════════════════╗
║ TRANSACTION INFORMATION ║
╚═════════════════════════╝
from: 0x13A19933267ec307c96f3dE8Ff8A2392C39263EB
to: 0x0a1c4c84213CB67C2517d442b93A2f1B0110158D (CrowdFunding)
chain: sepolia (11155111)
rpc: sepolia.rpc.thirdweb.com
data: 0x388a7ec10000000000000000000000000000000000000000000000000000000000000000
method: withdrawDonations(0)
╔═════════════════════╗
║ DEBUGGING RESOURCES ║
╚═════════════════════╝
Need helping debugging? Join our Discord: https://discord.gg/thirdweb
at ContractWrapper.formatError (contract-publisher-7f0a5ce8.browser.esm.js:7754:12)
at async ContractWrapper.sendTransactionByFunction (contract-publisher-7f0a5ce8.browser.esm.js:7696:17)
at async ContractWrapper.sendTransaction (contract-publisher-7f0a5ce8.browser.esm.js:7652:18)
at async ContractWrapper.call (contract-publisher-7f0a5ce8.browser.esm.js:7611:23)
at async withdraw (index.jsx:104:20)
at async handleWithdraw (WithdrawFromCampaigns.jsx:31:7)
Withdraw Function
// Constructor
constructor(uint256 _platformFee) payable {
manager == msg.sender;
platformFee = _platformFee;
balances[msg.sender] = msg.value;
}
// withdraw donations
function withdrawDonations(
uint256 _id
) public authorisedPerson(_id) returns (bool) {
(uint256 raisedAmount, uint256 fee) = calculatePlatformFee(_id);
//balances[msg.sender] = 0; // updating adress balance before atually withdrawing to prevent re-entracy attacks.
//send to campaign owner
//_payTo(campaigns[_id].owner, (raisedAmount - fee));
//payable(campaigns[_id].owner).transfer(raisedAmount - fee);
//send to platform
//_payTo(manager, fee);
payable(manager).transfer(fee);
emit Action(_id, "Funds Withdrawn", msg.sender, block.timestamp);
return true;
}
// function _payTo(address to, uint256 amount) internal {
// require(amount > 0, "Can't send 0");
// (bool success, ) = payable(to).call{value: amount}("");
// require(success);
// }
/* ... */
function calculatePlatformFee(
uint256 _id
) public view returns (uint, uint) {
uint raisedAmount = campaigns[_id].amountCollected;
uint fee = (raisedAmount * platformFee) / 100;
return (raisedAmount, fee);
}