How do I initiate a transaction from JavaScript?
Closed this issue · 3 comments
I can respond to transactions generated elsewhere via appendTx
. How do I create and send transactions from the application?
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
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 {}' }
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