Transaction class to manage Ethereum transactions thourgh it's lifecycle.
Recommended use:
example
const ethereumConnection = new EthereumConnection(config);
const rates = new Rates();
await rates.connect()
rates.setRate("USD", 121.12)
.[sign(privatekey, {from: acc, to:rates.address})] // optionally you can sign
.send([{from: acc}]) // from only needed if it's not signed
.onceTxHash( txHash => {.. })
.onceReceipt( receipt => { ...})
.onConfirmation( (confirmationNumber, receipt) => {...}
.onceReceiptConfirmed(5, receipt => {...})
.onceTxRevert( (error, receipt) => { ....})
// To catch errors you need to use txHash / confirmation / receipt getters:
try {
const txHash = await tx.getTxHash()
const txReceipt = await tx.getReceipt() // receipt as soon as got it (even with 0 confirmation)
const confirmedReceipt = await tx.getConfirmedReceipt(12) // receipt after x confirmation.
// receipt you need to check for receipt.status if tx was Reverted or not.
if (confirmedReceipt.status) {
// all good
} else {
// this tx was reverted
}
} catch (error) {
// These Promises are rejecting with sending errors or when txhash / receipt times out.
}
// Deprecated and discouraged but kept for backward compatibility with web3js style events:
tx.on[ce]("transactionHash" | "receipt" | "confirmation" | "error")
// This way it can be easily plugged into dapps which are handling web3js tx objects:
// augmint-js Transaction object can be a drop in as an almost direct replacement of webjs transactioObject
// To construct a transaction:
const web3TxObject = rates.instance.methods.setRate(CCY, 100)
const augmintRatesTx = new Transaction(ethereumConnection, web3TxObject, {gasLimit: 200000}); // you can set the gaslimit here or later at send() too
augmintRatesTx.send(...).onTxHash(...) // or sign().send() etc.
export
fires
transactionHash
fires
receipt fired as soon as a receipt received
fires
confirmation fired for each confirmation
fires
error fired in case of any error. kept for backward compatibility
fires
txRevert fired when tx was mined but with REVERT opcode. error also fired in this case for backward compatibility
Sign the transaction with the provided private key
and with the from, to, gas in ISendOptions.
ISendOptions can be set in [Transaction] constructor too.
make sure you set at least gasLimit and from.
Transaction class to manage Ethereum transactions thourgh it's lifecycle.
Recommended use:
const ethereumConnection = new EthereumConnection(config); const rates = new Rates(); await rates.connect() rates.setRate("USD", 121.12) .[sign(privatekey, {from: acc, to:rates.address})] // optionally you can sign .send([{from: acc}]) // from only needed if it's not signed .onceTxHash( txHash => {.. }) .onceReceipt( receipt => { ...}) .onConfirmation( (confirmationNumber, receipt) => {...} .onceReceiptConfirmed(5, receipt => {...}) .onceTxRevert( (error, receipt) => { ....})
// To catch errors you need to use txHash / confirmation / receipt getters: try { const txHash = await tx.getTxHash() const txReceipt = await tx.getReceipt() // receipt as soon as got it (even with 0 confirmation) const confirmedReceipt = await tx.getConfirmedReceipt(12) // receipt after x confirmation. // receipt you need to check for receipt.status if tx was Reverted or not. if (confirmedReceipt.status) { // all good } else { // this tx was reverted } } catch (error) { // These Promises are rejecting with sending errors or when txhash / receipt times out. }
// Deprecated and discouraged but kept for backward compatibility with web3js style events: tx.on[ce]("transactionHash" | "receipt" | "confirmation" | "error") // This way it can be easily plugged into dapps which are handling web3js tx objects: // augmint-js Transaction object can be a drop in as an almost direct replacement of webjs transactioObject
// To construct a transaction: const web3TxObject = rates.instance.methods.setRate(CCY, 100) const augmintRatesTx = new Transaction(ethereumConnection, web3TxObject, {gasLimit: 200000}); // you can set the gaslimit here or later at send() too augmintRatesTx.send(...).onTxHash(...) // or sign().send() etc.
transactionHash
receipt fired as soon as a receipt received
confirmation fired for each confirmation
error fired in case of any error. kept for backward compatibility
txRevert fired when tx was mined but with REVERT opcode. error also fired in this case for backward compatibility