'Write to ethereum wiithout metamask

I'm trying to write some data to Ethereum Rinkeby test network without using meta mask, But while calling the method i'm getting the error below , But my argument count is correct

UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 246): Error: Invalid number of arguments to Solidity function

The node code

    var Web3        = require('web3')
    var contract    = require("truffle-contract")
    var quickBooks    = require('../build/contracts/quickBooks.json')

    Web3.providers.HttpProvider.prototype.sendAsync = Web3.providers.HttpProvider.prototype.send;

    var provider    = new Web3.providers.HttpProvider("https://rinkeby.infura.io/v3/KEY")
    var quickBooksContract = contract(quickBooks);
    quickBooksContract.setProvider(provider);


    var writeToEthereum = async function(_json){
        //console.log(_json)
        var instance = await quickBooksContract.at('ADDRESS')
        var result = await instance.write.call(_json,_json.txhash,_json.createdt,"1",_json.write_set[0].set,{
from : "ADDRESS"
})
        console.log(result);
    }

Solidity

pragma experimental ABIEncoderV2;

contract quickBooks{

struct Tx{
    string txId;
    string timeStamp;
    string blockHash;
    string payLoad;
    string json;
}

mapping(string => Tx) private data;

function write(string _json,string _txId,string _timeStamp,string _blockHash,string _payLoad) public returns(bool success){
    data[_txId] = Tx(_txId,_timeStamp,_blockHash,_payLoad,_json);
    return true;
}

function read(string _txId)public returns(Tx){
    return data[_txId];
} 

}



Solution 1:[1]

Your call the contract function is wrong, you should pass the arguments to the function after the function name. The way you do it you are passing the arguments in the place of the call() options.

await instance.write(<params here>).call();

You can read more about this on the docs: https://web3js.readthedocs.io/en/1.0/web3-eth-contract.html

Solution 2:[2]

This can possibly be related to https://github.com/ethereum/web3.js/issues/1043

Check out the discussion there.

If you are using truffle try out:

Guys, Delete your build folder, then run the command.

npm run truffle migrate --reset --compile-all

I find it works best when running truffle locally to the folder rather than globally, due to the beta and different versions getting updated quickly recently. if you prefer the global approach try

truffle migrate --reset --compile-all

If this does not help, make sure you provide the correct data types. It might be that you are providing a string instead of an int.

If this does not help as well I will need more info on what version of web3 you are using and if you are using truffle and which version is it.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 nikos fotiadis
Solution 2 Dharman