Solidity Web3js: Invalid number of arguments to Solidity function error

0 votes

I'm currently using web3.js to use a function on form submit, which is transfer(address _to, uint256 _value)

I'm able to call contract function, but I get Error: Invalid number of arguments to Solidity function trying to use the transfer function, suppling both to address and amount of token.

Here part of my code:

function sendtoken(to, amount){

    var to = to; 
    var amount = amount; 
    var settx = contract.transfer(to,amount);

    return settx;
}

Calling it (don't worry, my contract correctly called in contract var

var formData = getFormObj("tokeform");

console.log(formData.destinationtoke);
console.log(formData.amounttoke);
var tx = sendtoken(destinationtoke, amounttoke);
var tx = JSON.stringify(tx, null, "  ");

console.log(tx);

This is where I get the error. Here the contract function:

function transfer(address _to, uint256 _value) {
    if (genesisAddress[_to]) throw;

    if (balances[msg.sender] < _value) throw;

    if (balances[_to] + _value < balances[_to]) throw;

    if (genesisAddress[msg.sender]) {
        minedBlocks = block.number - initialBlockCount;
        if(minedBlocks % 2 != 0){
            minedBlocks = minedBlocks - 1;
        }

        if (minedBlocks < 23652000) {
            availableAmount = rewardPerBlockPerAddress*minedBlocks;
            totalMaxAvailableAmount = initialSupplyPerAddress - availableAmount;
            availableBalance = balances[msg.sender] - totalMaxAvailableAmount;
            if (_value > availableBalance) throw;
        }
    }
    balances[msg.sender] -= _value;
    balances[_to] += _value;
    Transfer(msg.sender, _to, _value);
}

Can someone tell me how to solve this?

Oct 22, 2018 in Blockchain by slayer
• 29,050 points
428 views

1 answer to this question.

0 votes

Try this:

Change

console.log(formData.destinationtoke);
console.log(formData.amounttoke);
var tx = sendtoken(destinationtoke, amounttoke);

To :

console.log(formData.destinationtoke);
console.log(formData.amounttoke);
var tx = sendtoken(formData.destinationtoke, formData.amounttoke);
answered Oct 22, 2018 by Omkar
• 67,120 points

Related Questions In Blockchain

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

How to return data on execution of invoke function?

You can do this using a response ...READ MORE

answered Jul 23, 2018 in Blockchain by digger
• 27,620 points
27 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
105 views
0 votes
1 answer

How to get return value from solidity contract?

Once you call a constant function, you ...READ MORE

answered Aug 16, 2018 in Blockchain by slayer
• 29,050 points
385 views
+1 vote
3 answers

Removing double quotes from a string from JSON response in PHP

Just remove the json_encode call, and it should work: $resp ...READ MORE

answered Sep 12, 2018 in Blockchain by digger
• 27,620 points
2,104 views
0 votes
1 answer

Getting Invalid number of parameters for “undefined” when deploying smart contract

Try something like this for contracts that ...READ MORE

answered Oct 10, 2018 in Blockchain by Omkar
• 67,120 points
381 views
+1 vote
2 answers