Skip to main content

Create and Managing Accounts in MOI

Prerequisites

Before proceeding, ensure you’ve completed the guide on Creating a Participant and reviewed the documentation on Interactions.

Configuring a Account

Once a participant account has been created, you may need to update or configure it — for example, by adding new keys, revoking existing ones, or changing key weights.
This can be achieved using the AccountConfigure Interaction.

The following example demonstrates how to add a new key to an existing participant account.

const configureAccount = async() => {
// Create a new AccountConfigure Interaction
const account = new AccountConfigure(wallet);

const response = await account.addKey("0x000000004678e9f5bf2f66362ef5367fbc72efe7b419a5e7d851f57b00000000", 1000)
.send()

const receipt = await response.wait()

// Obtain the Interaction Hash
const ixhash = response.hash;
console.log("Interaction Hash:", ixhash);

// Wait for the Interaction Receipt
const receipt = await response.wait();
console.log("Interaction Receipt:", receipt);
}

Bingo! We have now successfully added a key to account. We can see from the receipt that it has been created.

Retrieving Account Keys

Now that we have successfully added a new account key, let us retrieve some information about it with an RPC Call.

Retrieving the Account Keys

const getAssetKeys = async() => {
// ID of the participant that got created previously
const id = "0x000000001ec28dabfc3e4ac4dfc2084b45785b5e9cf1287b63a4f46900000000"

// Use the moi.AccountMetaInfo RPC to fetch Account Metadata
const account_info = await provider.getAccountKeys(id)
console.log("Account Keys: ", account_info)
}

Performing Account Inherit in MOI

The AccountInherit Interaction facilitates inheriting configuration, or context
from one participant (or target account) to another within the network.
This operation is typically used when a participant inherits state-linked information from a parent or target account.


Executing Account Inherit

Let’s see how to execute an AccountInherit Interaction that inherits configuration or context from one account to another.

  const inheritAccount = async() => {
// Create a new AccountInherit Interaction
const account = new AccountInherit(wallet);
const id = "0x00000000513b40a069905a1b05bd28d8338ad4a2eff419d7972be75900000000";
const logicID = "0x20800000a6ba9853f131679d00da0f033516a2efe9cd53c3d54e1f9a00000000";

const response = await account.index(0).target(logicID)
.value(KMOI_ASSET_ID, id, 5000)

const receipt = await response.wait()

// Obtain the Interaction Hash
const ixhash = response.hash;
console.log("Interaction Hash:", ixhash);

// Wait for the Interaction Receipt
const receipt = await response.wait();
console.log("Interaction Receipt:", receipt);
}

🎉 Great! The account inheritance operation was successfully executed. From the receipt, we can confirm that the AccountInherit Interaction inherited context and cofiguration successfully from the target participant.

Retrieving the Context Info

  const getContextInfo = async() => {
// id of the participant that got created previously
const id = "0x00000000513b40a069905a1b05bd28d8338ad4a2eff419d7972be75900000000"

// Use the moi.ContextInfo RPC to fetch Context Info
const contextInfo = await provider.getContextInfo(id)
console.log("Context info: ", contextInfo)
}