1

I'm trying to pay royalties from a contract to multiple wallets, however the multiplication is always sending me to 0.

function withdraw_to_taxman() public view returns (uint256){
    uint256 balance = address(this).balance;
    uint256 withdraw_amount = balance * _tax_rate;
    return (withdraw_amount);
}

I'm writing this function to test how much I will withdraw, and then I would divide by 100 to get the actual withdrawal amount given that _tax_rate is a %. This withdraw_amount always returns 0, and I'm not sure why tax_rate is a uint256 that I am testing at the value of 1 I would greatly appreciate any help, thanks

1 Answer 1

1

Does your contract have a balance?

I tried the follwing code and it worked for me:

contract Contract {

    uint256 public _tax_rate = 1;

    function withdraw_to_taxman() public view returns (uint256){
        uint256 balance = address(this).balance;
        uint256 withdraw_amount = balance * _tax_rate;
        return (withdraw_amount);
    }

    receive() external payable {}

}

I sent 5 wei to the receive() external payable function so the balance of my contract is 5 wei. The _tax_rate value is 1, and when I called the withdraw_to_taxman function it returns 5.

I deployed it and verified it on Rinkeby so you can play around with it:

https://rinkeby.etherscan.io/address/0x83E6C7707B8610b32157e8897CEd5C8375F5C04F#readContract

https://rinkeby.etherscan.io/address/0x83E6C7707B8610b32157e8897CEd5C8375F5C04F#writeContract

I sent 0.000531 ether and set the tax_rate to 3 and withdraw_to_taxman returns: 1593000000000000, as expected.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.