Hello developers✋
I want to transfer msg value to another contracts when a user calls the mint function. But It failed😬! I don't know what is reason😞
This is my code:

address public poolContract;

I set the poolContract address in the constructor when I deploy it.

function mint(uint numberOfTokens) public payable {

(bool success, ) = poolContract.call{
value: (msg.value.mul(30)).div(100)
}("");

require(success, "Withdraw to prizePool faild!");
}
can you help me plz🙏

Dec 29, 2022, 5:01 AM
do you check if the msg.value is divisible by 100
example if I provide 0 ether
Dec 29, 2022, 5:04 AM
yes the value is okay .
Dec 29, 2022, 5:05 AM
ok
Dec 29, 2022, 5:05 AM
I think the problem is address of contract!
Dec 29, 2022, 5:05 AM
You mean poolContract address?
Dec 29, 2022, 5:06 AM
because if I put address of wallet replace poolcontract transfer will happen
yes
Ive tried it before
Dec 29, 2022, 5:07 AM
do you have the code of the poolContract
Dec 29, 2022, 5:07 AM
yes
Dec 29, 2022, 5:07 AM
Since you are just sending can you try
address( poolContract).transfer(msg.value)
Dec 29, 2022, 5:09 AM
okay
Dec 29, 2022, 5:10 AM
let me make it presentable
try
function mint(uint numberOfTokens) public payable {
bool success = payable(address(poolContract)).send(msg.value.mul(30)).div(100));
require(success, "Withdraw to prizePool faild!");
}
not tested though
Dec 29, 2022, 5:12 AM
Note: The called function should be payable if you send value and the value you send should be less than your current balance.
Dec 29, 2022, 5:14 AM
did you tried this
Dec 29, 2022, 5:16 AM
user send value to contract but here says insufficant balance
this the error
Dec 29, 2022, 5:16 AM
msg.value.mul(30)).div(100) this might be the culprit
try this msg.value.div(3) and see if it will work
split into 3
Dec 29, 2022, 5:17 AM
okay
I dint work
and I try it too

payable(prizePool).transfer(100);

error:
Note: The called function should be payable if you send value and the value you send should be less than your current balance.
Dec 29, 2022, 5:24 AM
payable(address(prizePool)).transfer(100);
transfer will throw an error if it fails
send will return a bool (true or false) if it failed or success
Dec 29, 2022, 5:26 AM
I dint work
I think transfer balance from contract to another contract is not possible
Dec 29, 2022, 5:40 AM
Then there is something else wrong, this is the standard way of sending ethers
it is, the contract must accept the ethers
Pool contract must implement
receive() external payable {}

fallback() external payable {}
also dont forget to add a means to withdraw the eth from the contract
else they will be stucked forever
Dec 29, 2022, 5:42 AM
function sendValue() onlyOwner public {
uint balance = address(this).balance;
payable(address(prizePool)).transfer(balance - 100);
}
I try it
but again faild
Dec 29, 2022, 5:43 AM
prizePool must implement this
can you share the prize pool contract
????
Dec 29, 2022, 5:44 AM
pragma solidity ^0.8.0;

contract PrizePool is Ownable {
using SafeMath for uint256;

function balance() public view returns (uint) {
return address(this).balance;
}

}
Dec 29, 2022, 5:46 AM
update to
pragma solidity ^0.8.0;

contract PrizePool is Ownable {
using SafeMath for uint256;

receive() external payable {}

fallback() external payable {}


function balance() public view returns (uint) {
return address(this).balance;
}

}
Dec 29, 2022, 5:47 AM
oh it works😍
Dec 29, 2022, 5:53 AM
great
Dec 29, 2022, 5:53 AM
🤩thank you
Dec 29, 2022, 5:53 AM
again dont forget to add a means to withdraw the ethers
Dec 29, 2022, 5:53 AM
sure
Dec 29, 2022, 5:54 AM
Why do you need SafeMath?
Dec 29, 2022, 6:11 AM
I just injected the fix in what he provided
he might have removed some codes
Dec 29, 2022, 6:12 AM

© 2024 Draquery.com All rights reserved.