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.
- Code
- Output
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);
}
// Console Output
Interaction Hash: 0x03eedbb2b17316b9eb4ff63350c8fe491203304bb6946fa5b5f9b114b227caa6
Interaction Receipt: {
ix_hash: '0x03eedbb2b17316b9eb4ff63350c8fe491203304bb6946fa5b5f9b114b227caa6',
status: 0,
fuel_used: '0x64',
ix_operations: [ { tx_type: '0x2', status: 0, data: null } ],
from: '0x000000001ec28dabfc3e4ac4dfc2084b45785b5e9cf1287b63a4f46900000000',
ts_hash: '0xfe58d8892a4a44ca51a9d3ae583ea4b997cf70d3e3fc3173e70c9061f0211851',
participants: [
{
id: '0x000000001ec28dabfc3e4ac4dfc2084b45785b5e9cf1287b63a4f46900000000',
height: '0x2',
transitive_link: '0xfa0891b827862c30f24d502482431031597e4b2de09b331109cd13de7028b061',
locked_context: '0x08d829a5911b07af4741fb77cd7d33d0cd6b81f1bf335314de9281ec8d30c4f6',
context_delta: null,
state_hash: '0xcbbe6be4d335886615bdfbfda3f70a0cea5916eadd36ae9f1b4db3cc5d068abb'
}
]
}
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
- Code
- Output
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)
}
// Console Output
Account Keys: [
{
id: '0x0',
publicKey: '0x1ec28dabfc3e4ac4dfc2084b45785b5e9cf1287b63a4f469c5051a29d5963bae',
weight: '0x3e8',
signature_algorithm: '0x0',
revoked: false,
sequence_id: '0x0'
},
{
id: '0x1',
publicKey: '0x000000004678e9f5bf2f66362ef5367fbc72efe7b419a5e7d851f57b00000000',
weight: '0x3e8',
signature_algorithm: '0x0',
revoked: false,
sequence_id: '0x0'
}
]
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.
- Code
- Output
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);
}
// Console Output
Interaction Hash: 0xe6c960958c9434c36c61e5b27a8c1a62f12a34ed395c78fb428682d0e7acf61e
Interaction Receipt: {
ix_hash: '0xe6c960958c9434c36c61e5b27a8c1a62f12a34ed395c78fb428682d0e7acf61e',
status: 0,
fuel_used: '0x64',
ix_operations: [ { tx_type: '0x3', status: 0, data: null } ],
from: '0x000000001ec28dabfc3e4ac4dfc2084b45785b5e9cf1287b63a4f46900000000',
ts_hash: '0x043c764fb6dda8054c257bc8a6d704e22b8dd7e374511b13a07e7f32ca13e2c9',
participants: [
{
id: '0x000000001ec28dabfc3e4ac4dfc2084b45785b5e9cf1287b63a4f46900000000',
height: '0x3',
transitive_link: '0xfe58d8892a4a44ca51a9d3ae583ea4b997cf70d3e3fc3173e70c9061f0211851',
locked_context: '0x08d829a5911b07af4741fb77cd7d33d0cd6b81f1bf335314de9281ec8d30c4f6',
context_delta: null,
state_hash: '0xff75dba2dbc7928c9d94f488d370df8e679c837e13e703cebc4a0022a5746cd0'
},
{
id: '0x108000004cd973c4eb83cdb8870c0de209736270491b7acc99873da100000000',
height: '0x0',
transitive_link: '0x072c748eec1830de50077952e56249a0718976df090a77b50219ba6522ccdfcd',
locked_context: '0x88d2e7fd7124741154c357efa994d4838b11f08bca914f9b2f26cc8ecd55e7cd',
context_delta: null,
state_hash: '0x0000000000000000000000000000000000000000000000000000000000000000'
},
{
id: '0x20800000a6ba9853f131679d00da0f033516a2efe9cd53c3d54e1f9a00000000',
height: '0x0',
transitive_link: '0x072c748eec1830de50077952e56249a0718976df090a77b50219ba6522ccdfcd',
locked_context: '0xe4cd45abf9de20991d1a73e77b9d7313aacbfc49a276cea89abc5ca8300e8479',
context_delta: null,
state_hash: '0x0000000000000000000000000000000000000000000000000000000000000000'
}
]
}
🎉 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
- Code
- Output
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)
}
// Console Output
Context info: {
consensus_nodes: [
'1116Uiu2HAmKzGHY5wzwE5ZibWuCo5FvQfdxY2z7b1XzcCJuDCbsHY7',
'1116Uiu2HAmR5LgKXYvJoXeDkptvq3qLAgjxBh9p5D2ND3fN9r5YvJ1',
'1116Uiu2HAmFXYSAQgnGbgecz4Dnb6WBHW6g1SvVzBqQ26WUoBfnNer'
],
storage_nodes: [],
inherited_account: '0x20800000a6ba9853f131679d00da0f033516a2efe9cd53c3d54e1f9a00000000',
sub_accounts: []
}