tendermint / js-abci

Javascript ABCI libraries
87 stars 42 forks source link

How do I initiate a transaction from JavaScript? #2

Closed NodeGuy closed 7 years ago

NodeGuy commented 8 years ago

I can respond to transactions generated elsewhere via appendTx. How do I create and send transactions from the application?

ebuchman commented 8 years ago

currently, you need to route them through the tendermint core rpc. you can use the broadcast_tx_sync endpoint (ie. http://localhost:46657/broadcast_tx_sync). If you're not running a core, you can use the tmsp-cli console to manually send messages directly to the app over the tmsp connection

NodeGuy commented 8 years ago

Would you please write an example of using http://localhost:46657/broadcast_tx_sync with curl?

Also, should I be using a JSONRPC library or js-wire to make the request?

I tried using a JSONRPC library and got an error:

  var jayson = require('jayson');

  var client = jayson.client.http({
    hostname: 'tendermint',
    port: 46657
  });

  client.request('broadcast_tx_sync', {tx: '0x00'}, function(err, response) {
    if(err) throw err;
    console.dir(response);
  });
{ jsonrpc: '2.0',
application_1 |   id: '',
application_1 |   result: null,
application_1 |   error: 'json: cannot unmarshal object into Go value of type []interface {}' }
ebuchman commented 8 years ago

Dave, you shouldn't need js-wire. See https://github.com/tendermint/fault-tolerance-demo (send_txs.sh) for an example setup (ie. broadcast tx with curl). Note I usually use the URI version of the API rather than JSONRPC, but it should work the same with JSONRPC. Also, txs should be hex but not 0x prefixed - that's something we can fix though