Options
All
  • Public
  • Public/Protected
  • All
Menu

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

Hierarchy

  • EventEmitter
    • Transaction

Index

Constructors

constructor

  • new Transaction(ethereumConnection: EthereumConnection, tx: PayableTransactionObject<any> | NonPayableTransactionObject<any>, sendOptions?: ISendOptions): Transaction
  • Creates an instance of Transaction.

    memberof

    Transaction

    Parameters

    • ethereumConnection: EthereumConnection
    • tx: PayableTransactionObject<any> | NonPayableTransactionObject<any>

      the web3.js transaction object

    • Optional sendOptions: ISendOptions

    Returns Transaction

Properties

Optional confirmationCount

confirmationCount: undefined | number

ethereumConnection

ethereumConnection: EthereumConnection

isTxSent

isTxSent: boolean = false

Optional sendError

sendError: any

sendOptions

sendOptions: ISendOptions

Optional sentTx

sentTx: IWeb3Tx

Optional signedTx

signedTx: ISignedTransaction

tx

tx: PayableTransactionObject<any> | NonPayableTransactionObject<any>

Optional txHash

txHash: undefined | string

Optional txReceipt

txReceipt: ITransactionReceipt

Static defaultMaxListeners

defaultMaxListeners: number

Methods

addListener

  • addListener(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

emit

  • emit(event: string | symbol, ...args: any[]): boolean
  • Parameters

    • event: string | symbol
    • Rest ...args: any[]

    Returns boolean

eventNames

  • eventNames(): Array<string | symbol>
  • Returns Array<string | symbol>

getConfirmedReceipt

  • getConfirmedReceipt(confirmationNumber?: number): Promise<ITransactionReceipt>
  • Parameters

    • Default value confirmationNumber: number = 1

    Returns Promise<ITransactionReceipt>

getMaxListeners

  • getMaxListeners(): number

getSignedTx

  • getSignedTx(): Promise<ISignedTransaction>
  • Returns Promise<ISignedTransaction>

getTxHash

  • getTxHash(): Promise<string>
  • Returns Promise<string>

getTxReceipt

  • getTxReceipt(): Promise<ITransactionReceipt>
  • Returns Promise<ITransactionReceipt>

listenerCount

  • listenerCount(type: string | symbol): number
  • Parameters

    • type: string | symbol

    Returns number

listeners

  • listeners(event: string | symbol): Function[]
  • Parameters

    • event: string | symbol

    Returns Function[]

off

  • off(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

on

  • on(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

onConfirmation

  • onConfirmation(callback: (confirmationNumber: number, receipt: ITransactionReceipt) => any): Transaction
  • Parameters

    • callback: (confirmationNumber: number, receipt: ITransactionReceipt) => any
        • (confirmationNumber: number, receipt: ITransactionReceipt): any
        • Parameters

          • confirmationNumber: number
          • receipt: ITransactionReceipt

          Returns any

    Returns Transaction

once

  • once(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

onceConfirmedReceipt

  • onceConfirmedReceipt(confirmationNumber: number, callback: (receipt: ITransactionReceipt) => any): Transaction
  • Parameters

    • confirmationNumber: number
    • callback: (receipt: ITransactionReceipt) => any
        • (receipt: ITransactionReceipt): any
        • Parameters

          • receipt: ITransactionReceipt

          Returns any

    Returns Transaction

onceReceipt

  • onceReceipt(callback: (receipt: ITransactionReceipt) => any): Transaction
  • Parameters

    • callback: (receipt: ITransactionReceipt) => any
        • (receipt: ITransactionReceipt): any
        • Parameters

          • receipt: ITransactionReceipt

          Returns any

    Returns Transaction

onceTxHash

  • onceTxHash(callback: (txHash: string) => any): Transaction
  • Parameters

    • callback: (txHash: string) => any
        • (txHash: string): any
        • Parameters

          • txHash: string

          Returns any

    Returns Transaction

onceTxRevert

  • onceTxRevert(callback: (error: any, receipt: ITransactionReceipt) => any): Transaction
  • Parameters

    • callback: (error: any, receipt: ITransactionReceipt) => any
        • (error: any, receipt: ITransactionReceipt): any
        • Parameters

          • error: any
          • receipt: ITransactionReceipt

          Returns any

    Returns Transaction

prependListener

  • prependListener(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

prependOnceListener

  • prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

rawListeners

  • rawListeners(event: string | symbol): Function[]
  • Parameters

    • event: string | symbol

    Returns Function[]

removeAllListeners

  • removeAllListeners(event?: string | symbol): this
  • Parameters

    • Optional event: string | symbol

    Returns this

removeListener

  • removeListener(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

send

  • Parameters

    • sendOptions: ISendOptions

    Returns Transaction

setMaxListeners

  • setMaxListeners(n: number): this
  • Parameters

    • n: number

    Returns this

sign

  • sign(privateKey: string, sendOptions: ISendOptions): Transaction
  • 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.

    memberof

    Transaction

    Parameters

    • privateKey: string

      Private key with leading 0x

    • sendOptions: ISendOptions

    Returns Transaction

    the [Transaction] object for chaining. Call [send] or [getSignedTranscation] on it

Static listenerCount

  • listenerCount(emitter: EventEmitter, event: string | symbol): number
  • deprecated

    since v4.0.0

    Parameters

    • emitter: EventEmitter
    • event: string | symbol

    Returns number

Generated using TypeDoc