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 };
  }
Name
Type
Description

msg

The message to convert.

Msg

export type Msg = Record<string, unknown>

updateOwnerMsg

Returns an update owner message.

updateOwnerMsg(newOwner: string, expiration?: Expiration) {
    return {
      ownership: {
        update_owner: {
          new_owner: newOwner,
          expiration
        }
      }
    };
  }
Name
Type
Description

newOwner

string

The address to assign as the new owner.

expiration

Optional expiration for the ownership request. Defaults to never.

Expiration

export type Expiration = ExpirationAtHeight | ExpirationAtTime | ExpirationNever;

// 
 
export interface ExpirationAtHeight {
  at_height: number
}
//Timestamp
export interface ExpirationAtTime {
  at_time: string
}
//Never Expire
export interface ExpirationNever {
  never: {}
}

updateOwner

Updates the owner for the given ADO.

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

    return resp;
  }
Name
Type
Description

newOwner

string

The address of the new owner.

addr

string

The address of the contract we are executing on.

expiration

Optional expiration. Defaults to never.

fee

Optional fee attached.

memo

string

Optional memo to attached.

Fee

export type Fee = number | StdFee | "auto"

Check StdFee.

updateAppContractMsg

Returns an update app contract message.

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

appContract

string

The new app contract.

updateAppContract

Updates the app contract for a given ADO.

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;
  }
Name
Type
Description

appContract

string

The new app contract.

addr

string

The address of the contract we are executing on.

fee

Optional fee to attach.

memo

string

Optional memo to attach.

registerModuleMsg

Returns a register module message.

registerModuleMsg(module: Module) {
    return { register_module: { module } };
  }
Name
Type
Description

module

Module

The module to register.

Module

export interface Module {
  name?: string;
  /** The address of the module */
  address: AndrAddress;
  /** Whether the module is mutable */
  is_mutable: boolean;
  /** The module idx (if it is already stored within a contract) */
  idx?: number;
}

AndrAddress

Object used to define an address used with the Andromeda ecosystem.

export type AndrAddress = string;

registerModule

Register a module with an ADO.

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;
  }
Name
Type
Description

module

The module to register.

addr

string

The address of the contract we are executing on.

fee

Optional fee to attach.

memo

string

Optional memo to attach.

deregisterModuleMsg

Returns a deregister module message.

 deregisterModuleMsg(id: number) {
    return {
      deregister_module: { module_idx: `${id}` },
    };
  }
Name
Type
Description

id

number

The id number (index) of the module to deregister.

deregisterModule

Deregisters a module with an ADO.

 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;
  }
Name
Type
Description

id

number

The id number (index) of the module to deregister.

addr

string

The address of the contract we are executing on.

fee

Optional fee to attach.

memo

string

Optional memo to attach.

alterModuleMsg

Returns am alter module message.

alterModuleMsg(id: number, module: Module) {
    return {
      alter_module: { module, module_idx: `${id}` },
    };
  }
Name
Type
Description

id

number

The id number (index) of the module to alter.

module

The new module to replace the old one.

alterModule

Alters a module within an ADO.

  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;
  }
Name
Type
Description

id

number

The id number (index) of the module to alter.

module

The new module to replace the old one.

addr

string

The address of the contract we are executing on.

fee

Optional fee to attach.

memo

string

Optional memo to attach.

Query Messages

ownerQuery

Returns an owner query message.

ownerQuery() {
    return { 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;
  }
Name
Type
Description

addr

string

The address of the contract we are querying.

isOwner

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

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

addr

string

The address we are checking.

contractAddr

string

The address of the contract we are querying.

typeQuery

Returns an ADO type query message.

typeQuery() {
    return { 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;
  }
Name
Type
Description

addr

string

The address of the contract we are querying.

publisherQuery

Returns a publisher query message.

 publisherQuery() {
    return { 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;
  }
Name
Type
Description

addr

string

The address of the contract we are querying.

createdHeightQuery

Returns a block height creation query.

createdHeightQuery() {
    return { 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;
  }
Name
Type
Description

addr

string

The address of the contract we are querying.

versionQuery

Returns a version query.

 versionQuery() {
    return { 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;
  }
Name
Type
Description

addr

string

The address of the contract we are querying.

moduleQuery

Returns a module query.

moduleQuery(id: string | number) {
    return { module: { id } };
  }
Name
Type
Description

id

string or number

The id of the module to query.

getModule

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

  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;
  }
Name
Type
Description

id

string or number

The id of the module to query.

addr

string

The address of the contract we are querying.

moduleIdsQuery

Returns a module IDs query.

  moduleIdsQuery() {
    return { module_ids: {} };
  }

getModuleIds

Gets all module IDs for a given ADO.

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

    return resp;
  }
Name
Type
Description

addr

string

The address of the contract we are querying.

getModules

Gets all modules for a given ADO.

  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;
  }
}
Name
Type
Description

addr

string

The address of the contract we are querying.

Last updated