ADOAPI Class
API to interact with Andromeda ADOs.
Copy export default class ADOAPI {
constructor (
protected client : AndromedaClient ,
protected address : string = ""
) {}
Execute Messages
andromedaReceive
Converts a message object to an Andromeda Execute message.
Copy protected andromedaReceive (msg: Msg) {
return { andr_receive : msg };
}
Msg
Copy export type Msg = Record < string , unknown >
updateOwnerMsg
Returns an update owner message.
Copy updateOwnerMsg (newOwner: string) {
return this .andromedaReceive ({ update_owner : { address : newOwner } });
}
updateOwner
Updates the owner for the given ADO.
Only accessible to the current owner.
Copy 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
Copy export type Fee = number | StdFee | "auto"
Check StdFee .
updateOperatorsMsg
Returns an update operators message.
Copy updateOperatorsMsg (operators: string[]) {
return this .andromedaReceive ({ update_operators : { operators } });
}
updateOperators
Updates the operators for a given ADO.
Only accessible to the current owner.
Copy 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.
Copy 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.
Copy 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.
Copy registerModuleMsg ( module : Module) {
return this .andromedaReceive ({ register_module : { module } });
}
Module
Copy 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.
Copy 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.
Copy 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.
Copy 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.
Copy 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.
Copy 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.
Copy 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.
Copy 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.
Copy 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.
Copy refreshAddressesMsg (startAfter ?: string , limit ?: number) {
return this .andromedaReceive ({
refresh_addresses : { start_after : startAfter , limit } ,
});
}
refreshAddresses
Refreshes multiple addresses.
Only accessible by the contract owner
Copy 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.
Copy protected andromedaQuery (msg: Msg) {
return { andr_query : msg };
}
operatorsQuery
Returns an operators query message.
Copy operatorsQuery () {
return this .andromedaQuery ({ operators : [] });
}
getOperators
Gets all operators for the provided ADO.
Copy 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.
Copy ownerQuery () {
return this .andromedaQuery ({ owner : {} });
}
getOwner
Gets the owner address for a provided ADO.
Copy 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.
Copy 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.
Copy typeQuery () {
return this .andromedaQuery ({ type : {} });
}
getType
Gets the ADO type for the provided ADO.
Copy 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
Copy publisherQuery () {
return this .andromedaQuery ({ original_publisher : {} });
}
getPublisher
Gets the original publisher of the given ADO.
Copy 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.
Copy createdHeightQuery () {
return this .andromedaQuery ({ block_height_upon_creation : {} });
}
getCreatedHeight
Gets the block height at which the given ADO was created.
Copy 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.
Copy versionQuery () {
return this .andromedaQuery ({ version : {} });
}
getVersion
Gets the version for a given ADO.
Copy 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.
Copy 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.
Copy 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.
Copy moduleIdsQuery () {
return this .andromedaQuery ({ module_ids : {} });
}
getModuleIds
Gets all module IDs for a given ADO.
Will error if the ADO does not implement modules
Copy 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.
Copy 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;
}
}