I have this code which gives JSON error in web3. I tested the connections and reading the contract and that all works. There is something wrong with the "data" key in the JSON. Somehow the addBonus function is not being understood. That is an update function.

addBonus is the correct name as follows -

function addBonus( string bonusType, uint bonusTarget,  uint bonusEndYear,
    uint bonusEndMonth, uint bonusEndDay, 
    string bonusToken, uint bonusAmount, string bonusName, uint ineq ) public { ...

Has someone an example of how to write a raw txn to update a contract using web3js and nodejs?

Calling code -

    var rawTransaction = {"from":myAddress,
    "gasPrice":web3js.toHex(20* 1e9),
   "data":contract.addBonus(bonusType, target, year, month, day, token, bonus, bonusName, ineq),

The error -

node_modules/web3/lib/web3/httpprovider.js:92 throw errors.InvalidResponse(request.responseText); ^

Error: Invalid JSON RPC response: ""

1 Answer 1


This works:

 "data":contract.addBonus.getData(bonusType, target, year, month, day, token, bonus, bonusName, ineq),

Your Answer

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

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