Send Transactions
Use the PegaSys Orchestrate client library to send transactions from JavaScript applications.
Prerequisites
- PegaSys Orchestrate JS client library installed
- Orchestrate running and connected to blockchain
- Contract registered on Orchestrate
- Sender account generated in Orchestrate
Import and initialize the broker
const Orchestrate = require('pegasys-orchestrate');
Send transaction envelope to Orchestrate
// produce sends an envelope to Orchestrate
// requesting a transaction execution
const produce = async broker => {
try {
const producer = await broker.producer();
try {
const msg = await producer.send({
// Specify chain ID to which Orchestrate is connected.
chainId: '2018',
// Specify name of a smart contract that has been previously registered
// on Orchestrate
call: {
contract: {
name: 'Counter',
tag: 'v0.1.0',
},
method: 'constructor()',
},
gas: 2000000,
// Specify sender address previously generated in Orchestrate prefunded with Ether
from: '0x7e654d251da770a068413677967f6d3ea2fea9e4',
});
console.log('Message sent: ', msg);
} catch (e) {
console.error(e);
}
} catch (e) {
console.error(e);
}
};
Receive transaction envelope from Orchestrate
// consume receives envelope from
// Orchestrate once transactions have been mined
const consume = async broker => {
try {
const consumer = await broker.consumer();
const consume = consumer.consume();
consume.on('message', message => {
console.log('Message consumed: ', message);
});
consume.on('error', error => {
console.error(error);
});
consume.on('offsetOutOfRange', error => {
console.error(error);
});
} catch (e) {
console.error(e);
}
};
TODO - add example