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, expiration?: Expiration) {
return {
ownership: {
update_owner: {
new_owner: newOwner,
expiration
}
}
};
}
newOwner
string
The address to assign as the new owner.
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.
Only accessible to the current owner.
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;
}
newOwner
string
The address of the new owner.
addr
string
The address of the contract we are executing on.
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 },
});
}
appContract
string
The new app contract.
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;
}
appContract
string
The new app contract.
addr
string
The address of the contract we are executing on.
memo
string
Optional memo to attach.
registerModuleMsg
Returns a register module message.
registerModuleMsg(module: Module) {
return { register_module: { module } };
}
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.
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 {
deregister_module: { module_idx: `${id}` },
};
}
id
number
The id number (index) of the module to deregister.
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;
}
id
number
The id number (index) of the module to deregister.
addr
string
The address of the contract we are executing on.
memo
string
Optional memo to attach.
alterModuleMsg
Returns am alter module message.
alterModuleMsg(id: number, module: Module) {
return {
alter_module: { module, module_idx: `${id}` },
};
}
id
number
The id number (index) of the module to alter.
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
addr
string
The address of the contract we are querying.
moduleQuery
Returns a module query.
moduleQuery(id: string | number) {
return { module: { id } };
}
id
string or number
The id of the module to query.
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;
}
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.
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;
}
addr
string
The address of the contract we are querying.
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;
}
}
addr
string
The address of the contract we are querying.
Last updated