I'm running parity with geth cli, invoked using the geth attach command. I have a contract already deployed using new call and stored in the object named trading. This contract contains a function which accepts ethers and updates the contract state:

function buy (uint qty) payable {
  if ( qty <= availableQty){
    availableQty = availableQty - qty;

Earlier, while using the geth cli with Ethereum itself, I could easily call the buy function via the command trading.buy.sendTransaction(10, {from:eth.accounts[0], value: 1000}). Now however with parity, the same command returns the following error:

TypeError: 'XMLHttpRequest' is not a function
at web3.js:4231:23
at web3.js:4245:19
at web3.js:6020:18
at web3.js:4995:36
at web3.js:4055:16
at web3.js:4141:16
at <anonymous>:1:1

Is there a workaround for this, or an alternate means of calling payable contract functions?

1 Answer 1


One alternative method for calling payable contract functions that worked for me was to use the JSON RPC interface. One thing to keep in mind is to unlock the from account apriori - I did this by using the --unlock flag while launching parity. By means of curl APIs, using the eth_sendTransaction call, I was able to post bulk transactions to the parity client:

> curl -X POST  -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_sendTransaction","params":[{"from": "0x2e88f518f770052d017ec1e6c6456c9fc227f403", "to": "0x8940fec332a089102dd1a6a8c0196ee39e25f66a", "data" : "0xd96a094a0000000000000000000000000000000000000000000000000000000000000005", "value" : "0x100"}],"id":1}' http://localhost:8545
> {"jsonrpc":"2.0","id":1,"result":"0x4d6d83df8b96f65da50b1b5a1b5f38af4b936d0bf71a90da9875542fbdced044"}

In the above command, the data field contains information about the function to call, as well as the arguments to be passed to that function. To understand more about the formation of the curl command, refer to How to call a contract method using the eth_call JSON-RPC API. Details of the various APIs available are listed at https://github.com/ethcore/parity/wiki/JSONRPC

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.