ethereumjs-tx

  • Version 2.1.2
  • Published
  • 66.2 kB
  • 2 dependencies
  • MPL-2.0 license

Install

npm i ethereumjs-tx
yarn add ethereumjs-tx
pnpm add ethereumjs-tx

Overview

A simple module for creating, manipulating and signing Ethereum transactions

Index

Classes

class FakeTransaction

class FakeTransaction extends Transaction {}
  • Creates a new transaction object that doesn't need to be signed.

    Parameter data

    A transaction can be initialized with its rlp representation, an array containing the value of its fields in order, or an object containing them by name.

    Parameter opts

    The transaction's options, used to indicate the chain and hardfork the transactions belongs to.

    See Also

    • Transaction

constructor

constructor(data?: any, opts?: TransactionOptions);

    property from

    from: Buffer;
    • Set from address to bypass transaction signing. This is not an optional property, as its getter never returns undefined.

    method hash

    hash: (includeSignature?: boolean) => Buffer;
    • Computes a sha3-256 hash of the serialized tx, using the sender address to generate a fake signature.

      Parameter includeSignature

      Whether or not to include the signature

    class Transaction

    class Transaction {}
    • An Ethereum transaction.

    constructor

    constructor(data?: any, opts?: TransactionOptions);
    • Creates a new transaction from an object with its fields' values.

      Parameter data

      A transaction can be initialized with its rlp representation, an array containing the value of its fields in order, or an object containing them by name.

      Parameter opts

      The transaction's options, used to indicate the chain and hardfork the transactions belongs to.

      Transaction objects implement EIP155 by default. To disable it, use the constructor's second parameter to set a chain and hardfork before EIP155 activation (i.e. before Spurious Dragon.)

      Example 1

      const txData = {
      nonce: '0x00',
      gasPrice: '0x09184e72a000',
      gasLimit: '0x2710',
      to: '0x0000000000000000000000000000000000000000',
      value: '0x00',
      data: '0x7f7465737432000000000000000000000000000000000000000000000000000000600057',
      v: '0x1c',
      r: '0x5e1d3a76fbf824220eafc8c79ad578ad2b67d01b0c2425eb1f1347e8f50882ab',
      s: '0x5bd428537f05f9830e93792f90ea6a3e2d1ee84952dd96edbae9f658f831ab13'
      };
      const tx = new Transaction(txData);

    property data

    data: Buffer;

      property gasLimit

      gasLimit: Buffer;

        property gasPrice

        gasPrice: Buffer;

          property nonce

          nonce: Buffer;

            property r

            r: Buffer;

              property raw

              raw: Buffer[];

                property s

                s: Buffer;

                  property to

                  to: Buffer;

                    property v

                    v: Buffer;

                      property value

                      value: Buffer;

                        method getBaseFee

                        getBaseFee: () => BN;
                        • the minimum amount of gas the tx must have (DataFee + TxFee + Creation Fee)

                        method getChainId

                        getChainId: () => number;
                        • returns chain ID

                        method getDataFee

                        getDataFee: () => BN;
                        • The amount of gas paid for the data in this tx

                        method getSenderAddress

                        getSenderAddress: () => Buffer;
                        • returns the sender's address

                        method getSenderPublicKey

                        getSenderPublicKey: () => Buffer;
                        • returns the public key of the sender

                        method getUpfrontCost

                        getUpfrontCost: () => BN;
                        • the up front amount that an account must have for this transaction to be valid

                        method hash

                        hash: (includeSignature?: boolean) => Buffer;
                        • Computes a sha3-256 hash of the serialized tx

                          Parameter includeSignature

                          Whether or not to include the signature

                        method serialize

                        serialize: () => Buffer;
                        • Returns the rlp encoding of the transaction

                        method sign

                        sign: (privateKey: Buffer) => void;
                        • sign a transaction with a given private key

                          Parameter privateKey

                          Must be 32 bytes in length

                        method toCreationAddress

                        toCreationAddress: () => boolean;
                        • If the tx's to is to the creation address

                        method toJSON

                        toJSON: (labels?: boolean) => { [key: string]: string } | string[];

                        method validate

                        validate: {
                        (): boolean;
                        (stringError: false): boolean;
                        (stringError: true): string;
                        };
                        • Validates the signature and checks to see if it has enough gas.

                        method verifySignature

                        verifySignature: () => boolean;
                        • Determines if the signature is valid

                        Interfaces

                        interface FakeTxData

                        interface FakeTxData extends TxData {}
                        • The data of a fake (self-signing) transaction.

                        property from

                        from?: BufferLike;
                        • The sender of the Tx.

                        interface TransactionOptions

                        interface TransactionOptions {}
                        • The transaction's options. This could be specified using a Common object, or chain and hardfork. Defaults to mainnet.

                        property chain

                        chain?: number | string;
                        • The chain of the transaction, default: 'mainnet'

                        property common

                        common?: Common;
                        • A Common object defining the chain and the hardfork a transaction belongs to.

                        property hardfork

                        hardfork?: string;
                        • The hardfork of the transaction, default: 'petersburg'

                        interface TransformableToBuffer

                        interface TransformableToBuffer {}
                        • Any object that can be transformed into a Buffer

                        method toBuffer

                        toBuffer: () => Buffer;

                          interface TxData

                          interface TxData {}
                          • A transaction's data.

                          property data

                          data?: BufferLike;
                          • This will contain the data of the message or the init of a contract

                          property gasLimit

                          gasLimit?: BufferLike;
                          • The transaction's gas limit.

                          property gasPrice

                          gasPrice?: BufferLike;
                          • The transaction's gas price.

                          property nonce

                          nonce?: BufferLike;
                          • The transaction's nonce.

                          property r

                          r?: BufferLike;
                          • EC signature parameter.

                          property s

                          s?: BufferLike;
                          • EC signature parameter.

                          property to

                          to?: BufferLike;
                          • The transaction's the address is sent to.

                          property v

                          v?: BufferLike;
                          • EC recovery ID.

                          property value

                          value?: BufferLike;
                          • The amount of Ether sent.

                          Type Aliases

                          type BufferLike

                          type BufferLike = Buffer | TransformableToBuffer | PrefixedHexString | number;
                          • A Buffer, hex string prefixed with 0x, Number, or an object with a toBuffer method such as BN.

                          type PrefixedHexString

                          type PrefixedHexString = string;
                          • A hex string prefixed with 0x.

                          Package Files (4)

                          Dependencies (2)

                          Dev Dependencies (29)

                          Peer Dependencies (0)

                          No peer dependencies.

                          Badge

                          To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                          You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/ethereumjs-tx.

                          • Markdown
                            [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/ethereumjs-tx)
                          • HTML
                            <a href="https://www.jsdocs.io/package/ethereumjs-tx"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>