1.0.43 • Published 2 years ago

@injectivelabs/tx-ts v1.0.43

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

🌟 Injective Protocol - TX TS

downloads npm-version license

Accessing decentralized finance through TypeScript (for Web and Node environment)

@injectivelabs/tx-ts is a TypeScript package for generating transactions from Messages easily that can be broadcasted to Injective. It also provides broadcasting clients that broadcast the transaction to Injective.

📚 Installation

yarn add @injectivelabs/tx-ts

📖 Documentation

There are three pieces of the tx-ts - generating a transaction, broadcasting a transactions and utility functions that can be performed on a transaction.

Generating a transaction

To generate a transaction that can be broadcasted to Injective, you can use the createTransaction function from the @injectivelabs/tx-ts package. Here is its definition and the params it receives / result it gives so its easier to understand:

export function createTransaction = (args: CreateTransactionArgs): CreateTransactionResult

/** @type {CreateTransactionArgs} */
export interface CreateTransactionArgs {
  message: MsgArg | MsgArg[] // the message that should be packed into the transaction
  memo: string // the memo to include in the transaction
  fee: StdFee // the fee to include in the transaction
  pubKey: string // the pubKey of the signer of the transaction in base64
  sequence: number // the sequence (nonce) of the signer of the transaction
  accountNumber: number // the account number of the signer of the transaction
  chainId: string // the chain id of the chain that the transaction is going to be broadcasted to
}

/** @type {CreateTransactionResult} */
export interface CreateTransactionResult {
  txRaw: TxRaw // the Tx raw that was created
  signDoc: SignDoc // the SignDoc that was created - used for signing of the transaction
  accountNumber: number // the account number of the signer of the transaction
  bodyBytes: Uint8Array // the body bytes of the transaction
  authInfoBytes: Uint8Array // the auth info bytes of the transaction
  signBytes: Uint8Array // the sign bytes of the transaction (SignDoc serialized to binary)
  signHashedBytes: Uint8Array // the sign bytes of the transaction (SignDoc serialized to binary) and hashed using keccak256
}

After the transaction is created, usually the signBytes of the result is getting signed and the signature gets appended on the txRaw that is also returned from the createTransaction function. Then, the txRaw is broadcasted to the Injective chain.

Broadcasting a transaction

There are two ways to broadcast a transaction to the Injective chain. First, as mentioned above we need to get the txRaw transaction (with added signatures) and use one of the two available clients exported from this package:

  • TxGrpcClient (which broadcast the transaction using the gRPC protocol), the endpoint passed to the constructor should be the sentryGrpcEndpoint
  • TxRestClient (which broadcast the transaction using the REST protocol), the endpoint passed to the constructor should be the sentryHttpEndpoint

There are pre-defined endpoints for different environments that can be found in the @injectivelabs/networks package.

Also, both of the clients have a simulate method which simulates the transaction before executing it on the chain.


⛑ Support

Reach out to us at one of the following places!

  • Website at injective.com
  • Twitter at @Injective
  • Discord at Discord
  • Telegram at Telegram

🔓 License

This software is licensed under the MIT license. See LICENSE for full disclosure.

1.0.29

2 years ago

1.0.28

2 years ago

1.0.33

2 years ago

1.0.32

2 years ago

1.0.31

2 years ago

1.0.30

2 years ago

1.0.37

2 years ago

1.0.36

2 years ago

1.0.35

2 years ago

1.0.34

2 years ago

1.0.39

2 years ago

1.0.38

2 years ago

1.0.40

2 years ago

1.0.43

2 years ago

1.0.42

2 years ago

1.0.41

2 years ago

1.0.19

2 years ago

1.0.2

2 years ago

1.0.18

2 years ago

1.0.1

2 years ago

1.0.17

2 years ago

1.0.16

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.22

2 years ago

1.0.21

2 years ago

1.0.20

2 years ago

1.0.26

2 years ago

1.0.25

2 years ago

1.0.24

2 years ago

1.0.23

2 years ago

1.0.27

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago