0

I work on Truffle and my project is simple. contract A should transfer some ether to contract B. contract A is funded enough. In contract A, there is a function called payment that performs the transfer and uint val is its parameter that tells the function the ether value to transfer. Whenever i try the function in Truffle console the following error occurs:

Error: invalid number value (arg="val", coderType="uint256", value=1000000000000000000)

I don't know how to assign a correct value as an argument to payment function.

contract A:

pragma solidity ^0.5.12;

contract A{

    event Payment(address receiver, uint value);

    function payment(uint val) public payable returns(string memory){
        address(uint160(0xae1b77270ae418bDd72e14e842F57D9EC2DBD1d8)).transfer(val);\\Transfer to contract B
        emit Payment(0xae1b77270ae418bDd72e14e842F57D9EC2DBD1d8, val);
        return "Payment done successfully";
    }

    function() external payable{}
} 

contract B:

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

    function() external payable{}
}

The command i tried in Truffle console:

truffle(develop)> A.deployed().then(function(ins){app=ins})
undefined
truffle(develop)> app.payment.sendTransaction(1000000000000000000)
0

Change this:

sendTransaction(1000000000000000000)

To this:

sendTransaction({value: '1000000000000000000'})
8
  • Actually, shouldn't it be val instead of value ? – Florian Castelain May 15 '20 at 12:04
  • @FlorianCastelain: No, it shouldn't. You're probably looking at function payment, which has nothing to do with all of this. And in any case, the names of input parameters in contract functions have no impact or meaning when you call those functions from an off-chain script (or from anywhere else for that matter). – goodvibration May 15 '20 at 12:15
  • @goodvibration: Thanks for your answer. It worked. Just a thing: if i want to set the recipient address as an argument in .sendTransaction(...) what shouls i do? As i realized payment does not need a corresponding parameter for that. Am i right? – Alireza May 15 '20 at 12:40
  • @A.Kiakojouri: You're welcome. What do you mean by "recipient"? – goodvibration May 15 '20 at 12:44
  • @goodvibration: I mean i want to type the address of contract B in .sendTransaction(...) on Truffle console instead i use address(uint160(0xae1b77270ae418bDd72e14e842F57D9EC2DBD1d8)).transfer(val) in contract A file. – Alireza May 15 '20 at 12:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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