InjectiveClient

Helper function to convert Uint8Array to JSON.

function arrayToJson(array: Uint8Array) {
  const jsonString = Buffer.from(array).toString("utf8");

  const parsedData = JSON.parse(jsonString);
  return parsedData;
}

Class

A client to interact with the Injective chain.

export default class InjectiveClient
  extends BaseChainClient
  implements ChainClient {
  declare public signingClient?: SigningStargateClient;
  declare public queryClient?: CosmWasmClient;
  public gasPrice?: GasPrice;

  private directSigner?: OfflineDirectSigner;

  protected preMessage(signed = true) {
    super.preMessage(signed);
    if (signed && !this.directSigner) {
      throw new Error("No signer assigned");
    }
  }

Methods

connect

Connects to the given chain. Assigns all clients used within the chain client, if a signer is provided a signing client is assigned.

Name
Type
Description

endpoint

string

The endpoint of the chain to connect to.

signer

CosmosOfflineDirectSigner or OfflineDirectSigner

Optional signer used to sign the messages.

options

Optional field to set the client options.

disconnect

Disconnects the from the connected client.

sign

Signs a given message with the connected signer.

Name
Type
Description

messages

The messages to sign.

fee

Fee to pay for the transaction. Defaults to auto if not specified.

memo

string

Optional memo to attach. Defaults to an empty string.

broadcast

Broadcasts a given transaction to the connected client.

Name
Type
Description

tx

The transaction to broadcast.

signAndBroadcast

Signs a given message before broadcasting it to the connected chain.

Name
Type
Description

messages

The messages to sign and broadcast.

fee

The fee to pay for signing and broadcasting the message. Defaults to auto if not specified.

memo

string

An optional memo to attach to the transaction.

EncodeObject

simulateMulti

Simulates all given messages and returns a gas fee estimate.

Name
Type
Description

messages

The messages to simulate.

fee

Fee amount to pay. Defaults to auto if not specified.

memo

string

Optional memo to attach to the transaction. Defaults to empty.

simulate

Simulates the given message and returns a gas fee estimate.

Name
Type
Description

message

The message to simulate.

fee

Fee payed to run the simulate. Defaults to auto if not specified.

memo

string or undefined

Optional memo to attach to the transaction.

execute

Executes a message on the specified contract.

Name
Type
Description

contractAddress

string

The contract address to execute on.

msg

The execute message.

fee

Fee amount to pay for the execution. Defaults to auto if not specified.

memo

string

Optional memo to attach to the transaction.

funds

Optional funds to attach along with the message.

Msg

simulateExecute

Simulates an execute message and returns a gas fee estimate.

Name
Type
Description

address

string

The contract address you are executing on.

msg

The execute message to simulate.

funds

The funds attached along with the message.

fee

Fee amount to pay. Defaults to auto if not specified.

memo

string or undefined

Optional memo to add to the transaction.

upload

Uploads given contract code (Uint8Array) to the chain.

Name
Type
Description

code

Uint8Array

The wasm binary code to upload to the connected client.

fee

Fee to pay for uploading. Defaults to auto if not specified.

memo

string

Optional memo to add to the transaction. Defaults to an empty string if not specified.

simulateUpload

Simulate an upload message and returns a gas fee estimate.

Name
Type
Description

code

Uint8Array

The wasm binary code to simulate uploading.

fee

Fee to pay for uploading. Defaults to auto if not specified.

memo

string or undefined

Optional memo to add to the transaction.

instantiate

Instantiates a contract with the given code id using the provided instantiate message.

Name
Type
Description

codeId

number

The code Id of the contract to instantiate.

msg

The instantiation message.

label

string

A label for the instantiation. Can be any string such as " instantiating a CW721" or "my_label" ect...

fee

Fee to pay for instantiation. Defaults to auto if not specified.

options

The options of an .instantiate() call. All properties are optional.

simulateInstantiate

Simulates an instantiation message and returns a gas fee estimate.

Name
Type
Description

codeId

number

The code Id of the contract to instantiate.

msg

The instantiation message.

label

string

A label for the instantiation. Can be any string such as " instantiating a CW721" or "my_label" ect...

fee

Fee to pay for instantiation. Defaults to auto if not specified.

options

The options of an .instantiate() call. All properties are optional.

migrate

Migrates a contract to a given code id.

Name
Type
Description

contractAddress

string

The address of the contract that you want to migrate.

codeId

number

The code Id to migrate to.

msg

The migrate message.

fee

Fee to pay for the migration. Defaults to auto if not specified.

memo

string

Optional memo to attach to the transaction.

simulateMigrate

Simulates a migrate message for a given contract address, code id and migrate message and returns a gas estimate.

Name
Type
Description

contractAddress

string

The contract address that you want to migrate.

codeId

number

The code Id to migrate to.

msg

Msg

The migrate message.

fee

Fee to pay to send the funds. Defaults to auto if not specified.

memo

string or undefined

Optional memo to attach to the transaction.

sendTokens

Sends tokens from the signing address to the provided receiving address.

Name
Type
Description

receivingAddress

string

The address to receive the tokens.

amount

Coin []

The funds to send.

fee

Fee to pay to send the funds. Defaults to auto if not specified.

memo

string

Optional memo to attach to the transaction.

Last updated