Skip to main content

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.

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)
}

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

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)
}

Retrieving Account State Information

Now we can retrieve the participant account state using the below RPC Call.

Retrieving the AccountState

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)
}