Fix my Smart Contract (payable problem)

my intention is to charge ETH/BNB to an address before deploying the smart contract
Payable should go through the receiver but not charging at all

contract SAMPLE is ERC20, Ownable {
    using Address for address payable;

and statement of
payable(serviceFeeReceiver_).sendValue(serviceFee_);

Full code below :
testnet : https://testnet.bscscan.com/address/0xac008161b30109492e533e5ff2da3386361d9da3#code

Just like you said above, you want to execute payable(serviceFeeReceiver_).sendValue(serviceFee_);, but it seems like you do not assign a valid value to serviceFeeReceiver_, I think it is always equal to address(0).

Maybe you can change your code to like this:

serviceFeeReceiver = serviceFeeReceiver_;
 => serviceFeeReceiver_ = serviceFeeReceiver;

Good day to everyone, I am currently having trouble with the payable in the constructor.

my intention is to charge ETH/BNB before deploying the smart contract
Payable should go through the receiver but not charging at all

contract SAMPLE is ERC20, Ownable {
    using Address for address payable;

and statement of
payable(serviceFeeReceiver_).sendValue(serviceFee_);

any ideas why this doesn't go through?

Full code below :
testnet : https://testnet.bscscan.com/address/0xac008161b30109492e533e5ff2da3386361d9da3#code

Hi Skyge,

I think the statement of address(0) is wrong since the serviceFeeReceiver is a valid address
my point is the "serviceFeeReceiver_" is bound to be in the constructor and will use an example address of 0x123
so in the payable code it should be "serviceFeeReceiver_"(eg. 0x123) will receive "serviceFee_"(eg. 0.1 ETH/BNB) upon deployment of the contract

serviceFeeReceiver = serviceFeeReceiver_;
 => serviceFeeReceiver_ = serviceFeeReceiver;

-I don't get this one, i tried to put this inside the constructor and I only receive errors.

issue fixed
default code
payable(serviceFeeReceiver_).sendValue(serviceFee_);
changed to :
payable(serviceFeeReceiver_).sendValue(msg.value);

msg.value corresponds to value(wei/gwei inputs) from remix

1 Like