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,370 points
2,846 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
• 69,220 points

Related Questions In Blockchain

0 votes
1 answer
0 votes
1 answer

Web3j v3.3.1 : Error while generating compiled solidity smart contracts which returns array of struct

Solidity does not support returning structs in ...READ MORE

answered Jun 19, 2018 in Blockchain by aryya
• 7,460 points
1,669 views
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
• 26,740 points
632 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
1,923 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,370 points
5,039 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
• 26,740 points
45,219 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,451 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
• 69,220 points
3,131 views
+1 vote
2 answers
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP