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 response = await wallet.sendInteraction({
fuel_price: 1,
fuel_limit: 200,
ix_operations: [
{
type: OpType.PARTICIPANT_CREATE,
payload: {
address: "0xeb2276237e066b8a346bb2eab96cd2d758d579622f8eb822865d2ce561d3d7b4,
amount: 10000
},
},
]
})
// 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: 0xba675589a8b9a86dce36daed785413d88c2bc81b830eea68d5a09fca04d6c3f6
Interaction Receipt: {
ix_hash: '0xba675589a8b9a86dce36daed785413d88c2bc81b830eea68d5a09fca04d6c3f6',
status: 0,
fuel_used: '0x64',
ix_operations: [ { tx_type: '0x1', status: 0, data: null } ],
from: '0x44ce1d50da7681c7a8a7277106f400134ff7f422bcc1d9fce5954c2531f54c66',
ts_hash: '0x6aa77dc2e129cf58ab25df4cb968e36ae72a92a27398bf7e4eb990064a22b13f',
participants: [
{
address: '0x44ce1d50da7681c7a8a7277106f400134ff7f422bcc1d9fce5954c2531f54c66',
height: '0x2',
transitive_link: '0xe82c358fd2ff710af1ae8da6625acc9eadcef79726c31ca4550492d361ada72b',
prev_context: '0xf0119e3fa3174bce972849d55db21e3c99485e0ade705214d5b05b59d5399d33',
latest_context: '0xf0119e3fa3174bce972849d55db21e3c99485e0ade705214d5b05b59d5399d33',
context_delta: null,
state_hash: '0xaca8bc2e44958fb63becbcde1d07dccfc42dc525731cf84d0cc38a9a133703ea'
},
{
address: '0xa6ba9853f131679d00da0f033516a2efe9cd53c3d54e1f9a6e60e9077e9f9384',
height: '0x2',
transitive_link: '0xe82c358fd2ff710af1ae8da6625acc9eadcef79726c31ca4550492d361ada72b',
prev_context: '0xe1e4a9cee05af1465d688b245439bc4ea0f42442eba364a086268dccf225dc7d',
latest_context: '0xe1e4a9cee05af1465d688b245439bc4ea0f42442eba364a086268dccf225dc7d',
context_delta: null,
state_hash: '0xcfad6fdc73b4f77956da080fe24abd16cda2b5e7db90e2590ae28de5e31c011d'
},
{
address: '0xeb2276237e066b8a346bb2eab96cd2d758d579622f8eb822865d2ce561d3d7b4',
height: '0x0',
transitive_link: '0x0000000000000000000000000000000000000000000000000000000000000000',
prev_context: '0x0000000000000000000000000000000000000000000000000000000000000000',
latest_context: '0x81f42d53e3c20c58921a2ee4afb8d03ebb80a4574dc723835e7e8436feb61358',
context_delta: {
behavioural_nodes: [
'3Wxz32Lfu6SmcSH3q4ZRa9gSM2Kd5XoUmmN6Uw9QjWEFfQuL9Ns9.16Uiu2HAm4oZ5jWPAxL4nFT5tZwNqXk4GAf6VbtTrJ1G19yBjGtZn',
'3WygabxbZ7WxAwFicbZhj8LNK12Xr7AdXwTTgkfjDLUC8XLoUzEK.16Uiu2HAm5nHnYQ7xe376HZd1iwwFQGRUrJjxg42SEynHmdSFFr44',
'3WyyyhXzN2VaxHFhmgH5YcHYjZbyEUErmuJkM4Qn1QhbizwQ3kjq.16Uiu2HAmHJ8FANpfPPChrP4BQow3GqpZNBX7oEX64yfa8jW42pRc'
],
random_nodes: null,
replaced_nodes: null
},
state_hash: '0x4495f3c5ccb8ecce8d849e2ddc19f01285b671fc5222f8f4f7a99ed3efb69db0'
}
]
}
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() => {
// Address of the participant that got created previously
const address = "0xeb2276237e066b8a346bb2eab96cd2d758d579622f8eb822865d2ce561d3d7b4"
// Use the moi.AccountMetaInfo RPC to fetch Account Metadata
const account_info = await provider.getAccountMetaInfo(address)
console.log("Account Meta data: ", account_info)
}
// Console Output
Account Meta data: {
"type": 4,
"address": "0xeb2276237e066b8a346bb2eab96cd2d758d579622f8eb822865d2ce561d3d7b4",
"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() => {
// Address of the participant that got created previously
const address = "0xeb2276237e066b8a346bb2eab96cd2d758d579622f8eb822865d2ce561d3d7b4"
// 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: {
"nonce": "0x0",
"acc_type": 4,
"balance": "0x311df7ff62d663a2abbf9b65823e6a4c75a46bf1101f7fc61c6b569cd28263e3",
"asset_approvals": "0x0000000000000000000000000000000000000000000000000000000000000000",
"asset_registry": "0x0000000000000000000000000000000000000000000000000000000000000000",
"context_hash": "0x81f42d53e3c20c58921a2ee4afb8d03ebb80a4574dc723835e7e8436feb61358",
"storage_root": "0x0000000000000000000000000000000000000000000000000000000000000000",
"logic_root": "0x0000000000000000000000000000000000000000000000000000000000000000",
"file_root": "0x0000000000000000000000000000000000000000000000000000000000000000"
}