AndromedaClient

Import

import AndromedaClient from "@andromedaprotocol/andromeda.js"

Class

A helper class for interacting with the Andromeda ecosystem

export default class AndromedaClient {
  public chainClient?: ChainClient;

  /**
   * Instantiate all provided APIs
   */
  public ado = new ADOAPI(this);
  public schema = new ADOSchemaAPI(this);
  public os = new OperatingSystemAPI(this);

  /**
   * A pre-message hook to check that the client is connected and functioning
   * @param signed Whether the message is signed
   */
  private preMessage() {
    if (!this.isConnected) throw new Error("Client not connected");
  }
Name
Type
Description

chainClient

Client used to interact with the chain, includes a query client when connected and a signing client when connected with a signer.

ado

API for shared ADO messages.

schema

API for schema specific messages.

os

API for OS contracts specific messages.

Methods

connect

Connects to a new chain by endpoint.

Name
Type
Description

endpoint

string

The endpoint of the chain to connect to.

kernelAddress

string

The contract address of the kernel contract.

addressPrefix

string

The prefixo of the connecting address.

signer

Optional signer used to sign the messages.

options

Optional field to set the client options.

assignKeyAddresses

Assigns the kernel address and fetches the VFS and ADODB addresses.

Name
Type
Description

kernelAddress

string

The address of the kernel contract to assign.

disconnect

Disconnects the assigned clients.

isConnected

Getter method to indicate whether the client is currently connected.

signAndBroadcast

Wrapper function for CosmWasm sign and broadcast. Creates a transaction with the given messages, fee and memo and then signs and broadcasts the transaction.

Name
Type
Description

messages

The messages to broadcast.

fee

The fee to pay for the message.

memo

string

optional memo to the transaction.

Fee

Check StdFee.

EncodeObject

upload

Wrapper function for CosmWasm upload. Uploads code and returns a receipt, including the code ID.

Name
Type
Description

code

Uint8Array

The code to upload.

fee

The fee to pay. Defaults to auto if not specified.

memo

string

Optional memo to attatch.

execute

Wrapper function for CosmWasm execute. Execute the defined message.

Name
Type
Description

contractAddress

string

The contract address to execute on.

msg

The message to execute.

fee

The fee to pay.

memo

string

Optional memo to attach along a message.

funds

readonly Coin[]

Optional funds to send along the message.

instantiate

Wrapper function for CosmWasm instantiate. Instantiates the defined message.

Name
Type
Description

codeId

number

The code ID of the contract to instantiate.

msg

The instantiation message.

label

string

The label attached to instantiation.

fee

string

The fee to pay. Defaults to auto if not specified.

options

Options for the instantiate call. Includes optional admin, funds, and memo.

queryContract

Makes a smart query on the contract, returns the parsed JSON document. Promise is rejected when contract does not exist, for invalid query format, and for invalid response format.

Name
Type
Description

address

string

The address of the contract to query.

query

The query message.

Msg

migrate

Wrapper function to ComsWasm migrate.

Name
Type
Description

contractAddress

string

The contract address to migrate.

codeId

number

The code Id to migrate to.

msg

The migrate message.

fee

The fee to pay. Defaults to auto if not specified.

memo

string

Optional memo to attach.

simulateMigrate

Estimates the gas cost of sending a migrate transaction.

Name
Type
Description

address

string

The contract address 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.

estimateMigrateFee

Estimates the fee cost of sending a migrate transaction.

Name
Type
Description

address

string

The contract address to migrate.

codeId

number

The code Id to migrate to.

msg

The migrate message.

simulateExecute

Estimates the gas cost of sending an execute transaction.

Name
Type
Description

address

string

The contract address to simulate the execute for.

msg

The message of the execute.

funds

The amount of funds attached to the message.

fee

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

memo

string

Optional memo to attach.

simulateMsgs

Simulates provided messages returning an estimated gas cost.

Name
Type
Description

msgs

The messages to simulate.

fee

Fee to pay.

memo

string

Optional memo to attach.

simulateInstantiate

Estimates the gas cost of sending an instantiate transaction and returns it.

Name
Type
Description

codeId

number

The code Id of the contract to instantiate.

msg

The instantiation message.

label

string

The label attached to the instantiation.

fee

Fee to pay.

memo

string

Optional memo to attach.

simulateUpload

Estimates the gas cost of sending an upload transaction.

Name
Type
Description

wasmByteCode

Uint8Array

The wasm code to simulate uploading.

estimateUploadFee

Estimates the fee cost of sending an upload transaction.

Name
Type
Description

wasmByteCode

Uint8Array

The wasm code to simulate uploading.

calculateFee

Wrapped around cosmjs calculateFee using client's set gasPrice. Errors if no gas price provided.

Name
Type
Description

gas

number

The amount of gas.

estimateFee

Simulates provided messages and calculates an estimated fee.

Name
Type
Description

msgs

EncodeObject[]

The messages to estimate the fee for.

fee

The fee to pay.

memo

string

Optional memo to attach.

estimateExecuteFee

Estimates the fee cost of sending an execute transaction.

The fields are the same as in execute but will return an estimate of the fees instead of executing the message.

estimateInstantiationFee

Estimates the fee cost of sending an instantiate transaction and returns it.

Name
Type
Description

codeId

number

The code ID of the contract to instantiate.

msg

The instantiation message

label

string

The label attached to instantiation

memo

string

Optional memo to attach.

getBalance

Gets the balance for a given address and denom. Defaults to the signing wallet address if none provided.

Name
Type
Description

denom

string

The denom to check the balance for.

address

string

The address to check the balance for. If not specified, the address of the connected signer is used.

getSentTxsByAddress

Gets all send transactions for a given address.

Name
Type
Description

addr

string

The address to get the send transactions for.

getTx

Wrapper around the cosm.js client's getTx function.

Name
Type
Description

hash

string

The tx hash.

getTxsByContract

Gets all transactions sent to a contract.

Name
Type
Description

addr

string

The contract address to check transactions for.

getBankTxsByAddress

Gets all bank messages sent to or from an address.

Name
Type
Description

addr

string

The address to check the bank messages for.

getAllTxsByAddress

Queries all possible transactions for a given address.

Name
Type
Description

addr

string

The address to get all the transactions for.

sendTokens

wrapper around the cosm.js client's sendTokens function. Send tokens to another address.

Name
Type
Description

receivingAddress

string

The address to receive the tokens.

amount

The amount of tokens to send.

fee

Fee to pay for sending the tokens. Defaults to auto if not specified.

memo

string

An optional memo to attach.

Helper Function

JsonToArray

Helper function to convert JSON to Uint8Array

Name
Type
Description

json

Record<string, any>

JSON object to convert to Uint8Array

Returns the Uint8Array.

Last updated