Create and Managing Participants in MOI
Prerequisites
To effectively utilise this guide, we recommend reading our guide on Submitting an Interaction and the documentation regarding, Interactions.
Creating an Participant
We must first create an account for the participant in order to perform other type of operations. We can do this using the ParticipantCreate Interaction
and specify the appropriate parameters and metadata. For the sake of this guide, we will first create an participant.
- Code
- Output
const createParticipant = async() => {
// Submit the ParticipantCreate Interaction and await the response
const participant = new ParticipantCreate(wallet);
const response = await participant.id("0x000000004678e9f5bf2f66362ef5367fbc72efe7b419a5e7d851f57b00000000")
.addKey("0x00000000513b40a069905a1b05bd28d8338ad4a2eff419d7972be75900000000", 1000, 0)
.value(KMOI_ASSET_ID, "0x00000000513b40a069905a1b05bd28d8338ad4a2eff419d7972be75900000000", 5000)
.send()
// Obtain the Interaction Hash and print it
const ixhash = response.hash;
console.log("Interaction Hash: ", ixhash)
// Poll for the Interaction Receipt and print it
const receipt = await response.wait()
console.log("Interaction Receipt: ", receipt)
}
// Console Output
Interaction Hash: 0x1a403f18c5258b1abc56d22fee88c7a2155f2234f1879b8eae5bbe1852346970
Interaction Receipt: {
ix_hash: '0x1a403f18c5258b1abc56d22fee88c7a2155f2234f1879b8eae5bbe1852346970',
status: 1,
fuel_used: '0x64',
ix_operations: [ { tx_type: '0x1', status: 1, data: null } ],
from: '0x000000001ec28dabfc3e4ac4dfc2084b45785b5e9cf1287b63a4f46900000000',
ts_hash: '0xfa0891b827862c30f24d502482431031597e4b2de09b331109cd13de7028b061',
participants: [
{
id: '0x000000001ec28dabfc3e4ac4dfc2084b45785b5e9cf1287b63a4f46900000000',
height: '0x1',
transitive_link: '0x072c748eec1830de50077952e56249a0718976df090a77b50219ba6522ccdfcd',
locked_context: '0x08d829a5911b07af4741fb77cd7d33d0cd6b81f1bf335314de9281ec8d30c4f6',
context_delta: null,
state_hash: '0xa846a8fe5ddb7adaf0e759cb6cf79838c748c76da1e788b92f7baa21374850fa'
},
{
id: '0x000000004678e9f5bf2f66362ef5367fbc72efe7b419a5e7d851f57b00000000',
height: '0x0',
transitive_link: '0x0000000000000000000000000000000000000000000000000000000000000000',
locked_context: '0x0000000000000000000000000000000000000000000000000000000000000000',
context_delta: [Object],
state_hash: '0x0000000000000000000000000000000000000000000000000000000000000000'
},
{
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'
}
]
}
Bingo! We have now successfully created an pariticpant. We can see from the receipt that it has been created.
Retrieving Account Meta Information
Now that we have successfully created our Participant, let us retrieve some information about it with an RPC Call.
Retrieving the Metadata of an Account
- Code
- Output
const getAssetInfo = 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.getContextInfo(id)
console.log("Account Meta data: ", account_info)
}
// Console Output
Account Meta data: {
"type": 4,
"id": "0x000000001ec28dabfc3e4ac4dfc2084b45785b5e9cf1287b63a4f46900000000",
"height": "0x0",
"tesseract_hash": "0x6aa77dc2e129cf58ab25df4cb968e36ae72a92a27398bf7e4eb990064a22b13f"
}
Retrieving Account State Information
Now we can retrieve the participant account state using the below RPC Call.
Retrieving the AccountState
- Code
- Output
const getAssetInfo = async() => {
// ID of the participant that got created previously
const id = "0x00000000513b40a069905a1b05bd28d8338ad4a2eff419d7972be75900000000"
// Use the moi.AccountState RPC to fetch Account State
const account_state = await provider.getAccountState(address)
console.log("Account State: ", account_state)
}
// Console Output
Account State: {
"acc_type": 3,
"asset_deeds": "0x0000000000000000000000000000000000000000000000000000000000000000",
"context_hash": "0x88d2e7fd7124741154c357efa994d4838b11f08bca914f9b2f26cc8ecd55e7cd",
"storage_root": "0xc28031ef5f805a6a3fbbe22b4e28450597b0974e4e9b050d01d9ad7ccfaf9f56",
"asset_root": "0xab9e3a34aba2a79b1add7ccb2c55b98fb655a80e2b48ea74d964dcfceb9b05b3",
"logic_root": "0xcf094b8933fe629d3e9e23786fe31365502732d5aeb9ba23a60c01899c790b55",
"file_root": "0x0000000000000000000000000000000000000000000000000000000000000000",
"keys_hash": "0x0000000000000000000000000000000000000000000000000000000000000000"
}