API Classes

ADOAPI Class

API to interact with Andromeda ADOs.

export default class ADOAPI {
  constructor(
    protected client: AndromedaClient,
    protected address: string = ""
  ) {}

Execute Messages

andromedaReceive

Converts a message object to an Andromeda Execute message.

 protected andromedaReceive(msg: Msg) {
    return { andr_receive: msg };
  }

Msg

export type Msg = Record<string, unknown>

updateOwnerMsg

Returns an update owner message.

updateOwnerMsg(newOwner: string) {
    return this.andromedaReceive({ update_owner: { address: newOwner } });
  }

updateOwner

Updates the owner for the given ADO.

Only accessible to the current owner.

async updateOwner(
    newOwner: string,
    addr: string = this.address,
    fee?: Fee,
    memo?: string
  ) {
    const msg = this.updateOwnerMsg(newOwner);
    const resp = await this.client.execute(addr, msg, fee, memo);

    return resp;
  }

Fee

export type Fee = number | StdFee | "auto"

Check StdFee.

updateOperatorsMsg

Returns an update operators message.

updateOperatorsMsg(operators: string[]) {
    return this.andromedaReceive({ update_operators: { operators } });
  }

updateOperators

Updates the operators for a given ADO.

Only accessible to the current owner.

async updateOperators(
    operators: string[],
    addr: string = this.address,
    fee?: Fee,
    memo?: string
  ) {
    const msg = this.updateOperatorsMsg(operators);
    const resp = await this.client.execute(addr, msg, fee, memo);

    return resp;
  }

updateAppContractMsg

Returns an update app contract message.

updateAppContractMsg(appContract: string) {
    return this.andromedaReceive({
      update_app_contract: { address: appContract },
    });
  }

updateAppContract

Updates the app contract for a given ADO.

Only accessible to the current owner.

async updateAppContract(
    appContract: string,
    addr: string = this.address,
    fee?: Fee,
    memo?: string
  ) {
    const msg = this.updateAppContractMsg(appContract);
    const resp = await this.client.execute(addr, msg, fee, memo);

    return resp;
  }

registerModuleMsg

Returns a register module message.

  registerModuleMsg(module: Module) {
    return this.andromedaReceive({ register_module: { module } });
  }

Module

export interface Module {
  module_type: string;
  address: AndrAddress;
  is_mutable: boolean;
}

AndrAddress

An interface used to reference another ADO contract. Can be either an address or identifier of an ADO in an app.

export interface AndrAddress {
  identifier: string;
}

registerModule

Register a module with an ADO.

Only accessible by the contract owner.

Will error if the ADO does not implement modules.

  async registerModule(
    module: Module,
    addr: string = this.address,
    fee?: Fee,
    memo?: string
  ) {
    const msg = this.registerModuleMsg(module);
    const resp = await this.client.execute(addr, msg, fee, memo);

    return resp;
  }

deregisterModuleMsg

Returns a deregister module message.

  deregisterModuleMsg(id: number) {
    return this.andromedaReceive({ deregister_module: { module_idx: id } });
  }

deregisterModule

Deregisters a module with an ADO.

Only accessible by the contract owner.

Will error if the ADO does not implement modules.

 async deregisterModule(
    id: number,
    addr: string = this.address,
    fee?: Fee,
    memo?: string
  ) {
    const msg = this.deregisterModuleMsg(id);
    const resp = await this.client.execute(addr, msg, fee, memo);

    return resp;
  }

alterModuleMsg

Returns am alter module message.

 alterModuleMsg(id: number, module: Module) {
    return this.andromedaReceive({ alter_module: { module, module_idx: id } });
  }

alterModule

Alters a module within an ADO.

Only accessible by the contract owner.

Will error if the ADO does not implement modules.

  async alterModule(
    id: number,
    module: Module,
    addr: string = this.address,
    fee?: Fee,
    memo?: string
  ) {
    const msg = this.alterModuleMsg(id, module);
    const resp = await this.client.execute(addr, msg, fee, memo);

    return resp;
  }

refreshAddressMsg

Returns a refresh address message.

 refreshAddressMsg(key: string) {
    return this.andromedaReceive({ refresh_address: { address: key } });
  }

refreshAddress

Refreshes any AndrAddresses within the ADO for the specified key. This is used when we have saved addresses in a primitve and want to update the cashe in case they change.

Only accessible by the contract owner.

async refreshAddress(
    key: string,
    addr: string = this.address,
    fee?: Fee,
    memo?: string
  ) {
    const msg = this.refreshAddressMsg(key);
    const resp = await this.client.execute(addr, msg, fee, memo);

    return resp;
  }

refreshAddressesMsg

Returns a refresh addresses message.

  refreshAddressesMsg(startAfter?: string, limit?: number) {
    return this.andromedaReceive({
      refresh_addresses: { start_after: startAfter, limit },
    });
  }

refreshAddresses

Refreshes multiple addresses.

Only accessible by the contract owner

 async refreshAddresses(
    startAfter?: string,
    limit?: number,
    addr: string = this.address,
    fee?: Fee,
    memo?: string
  ) {
    const msg = this.refreshAddressesMsg(startAfter, limit);
    const resp = await this.client.execute(addr, msg, fee, memo);

    return resp;
  }

Query Messages

andromedaQuery

Converts a message object to an Andromeda Query message.

  protected andromedaQuery(msg: Msg) {
    return { andr_query: msg };
  }

operatorsQuery

Returns an operators query message.

  operatorsQuery() {
    return this.andromedaQuery({ operators: [] });
  }

getOperators

Gets all operators for the provided ADO.

  async getOperators(addr: string = this.address) {
    const query = this.operatorsQuery();
    const resp = await this.client.queryContract<{ operators: string[] }>(
      addr,
      query
    );

    return resp.operators;
  }

ownerQuery

Returns an owner query message.

 ownerQuery() {
    return this.andromedaQuery({ owner: {} });
  }

getOwner

Gets the owner address for a provided ADO.

async getOwner(addr: string = this.address) {
    const query = this.ownerQuery();
    const resp = await this.client.queryContract<{ owner: string }>(
      addr,
      query
    );
    return resp.owner;
  }

isOperatorOrOwner

Validates if a given address is an owner or operator for the given ADO.

  async isOperatorOrOwner(addr: string, contractAddr: string = this.address) {
    const operators = await this.getOperators(contractAddr);
    const owner = await this.getOwner(contractAddr);
    return operators.includes(addr) || owner === addr;
  }

typeQuery

Returns an ADO type query message.

  typeQuery() {
    return this.andromedaQuery({ type: {} });
  }

getType

Gets the ADO type for the provided ADO.

 async getType(addr: string = this.address) {
    const query = this.typeQuery();
    const resp = await this.client.queryContract<{ ado_type: string }>(
      addr,
      query
    );

    return resp.ado_type;
  }

publisherQuery

  publisherQuery() {
    return this.andromedaQuery({ original_publisher: {} });
  }

getPublisher

Gets the original publisher of the given ADO.

  async getPublisher(addr: string = this.address) {
    const query = this.publisherQuery();
    const resp = await this.client.queryContract<{
      original_publisher: string;
    }>(addr, query);

    return resp.original_publisher;
  }

createdHeightQuery

Returns a block height creation query.

  createdHeightQuery() {
    return this.andromedaQuery({ block_height_upon_creation: {} });
  }

getCreatedHeight

Gets the block height at which the given ADO was created.

 async getCreatedHeight(addr: string = this.address) {
    const query = this.createdHeightQuery();
    const resp = await this.client.queryContract<{ block_height: number }>(
      addr,
      query
    );

    return resp.block_height;
  }

versionQuery

Returns a version query.

  versionQuery() {
    return this.andromedaQuery({ version: {} });
  }

getVersion

Gets the version for a given ADO.

  async getVersion(addr: string = this.address) {
    const query = this.versionQuery();
    const resp = await this.client.queryContract<{ version: string }>(
      addr,
      query
    );

    return resp.version;
  }

moduleQuery

Returns a module query.

  moduleQuery(id: string | number) {
    return this.andromedaQuery({ module: { id } });
  }

getModule

Gets the module of the specified id for a given ADO.

Will error if the ADO does not implement modules.

  async getModule(id: string | number, addr: string = this.address) {
    const query = this.moduleQuery(id);
    const resp = await this.client.queryContract<Module>(addr, query);

    return resp;
  }

moduleIdsQuery

Returns a module IDs query.

  moduleIdsQuery() {
    return this.andromedaQuery({ module_ids: {} });
  }

getModuleIds

Gets all module IDs for a given ADO.

Will error if the ADO does not implement modules

  async getModuleIds(addr: string = this.address) {
    const query = this.moduleIdsQuery();
    const resp = await this.client.queryContract<string[]>(addr, query);

    return resp;
  }

getModules

Gets all modules for a given ADO.

Uses several queries so response may be slow.

  async getModules(addr: string = this.address) {
    const ids = await this.getModuleIds(addr);
    const modulePromises = [];

    for (let i = 0; i < ids.length; i++) {
      modulePromises.push(this.getModule(ids[i], addr));
    }

    const modules = await Promise.all(modulePromises);

    return modules;
  }
}

Last updated