A helper class for interacting with the Andromeda ecosystem
exportdefaultclassAndromedaClient{public chainClient?:ChainClient;/** * Instantiate all provided APIs*/public ado =newADOAPI(this);public schema =newADOSchemaAPI(this);public os =newOperatingSystemAPI(this);/** * A pre-message hook to check that the client is connected and functioning * @paramsigned Whether the message is signed*/privatepreMessage(){if (!this.isConnected) thrownewError("Client not connected");}
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.
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.
calculcateFee(gas: number) {
const gasPrice = this.chainClient?.gasPrice;
if (!gasPrice)
throw new Error(
"No gas prices provided for client. Cannot simulate Tx fee."
);
const multiplier = 1.3; // Unsure why this is necessary but is added during simulateTx in cosmjs
return calculateFee(Math.round(gas * multiplier), gasPrice);
}
async estimateFee(
msgs: readonly EncodeObject[],
fee?: StdFee,
memo?: string
) {
const gas = await this.simulateMsgs(msgs, fee, memo);
if (!gas) {
throw new Error("Could not simulate transaction");
}
return this.calculcateFee(gas);
}
const JsonToArray = function (json: Record<string, any>) {
var str = JSON.stringify(json, null, 0);
var ret = new Uint8Array(str.length);
for (var i = 0; i < str.length; i++) {
ret[i] = str.charCodeAt(i);
}
return ret;
};