Skip to main content

Using Managed Wallets

Managed wallets offer a seamless user experience by allowing you to create blockchain wallets for your users without requiring them to download any apps or take additional steps.

This transparency lets users easily track the movement of items in and out of their wallets, aiding in user onboarding and providing clear, immutable on-chain data to track their tokens.

What you'll need:
  • Some Enjin Coin on Enjin Matrixchain to pay for Transaction Fees.
    You can obtain cENJ (Canary ENJ) for testing from the Canary faucet.
  • An Enjin Platform Account.
  • A Collection and a Token to add to the wallet.

Create Managed Wallets

To create a Managed wallet, run the CreateWallet mutation, with a unique ID as a parameter.

Choose a unique externalId for each player/user that can be cross-referenced later. This unique identifier should be something already associated with the player in your database, such as a player ID or username.
By doing so, you will be able to consistently link the Managed Wallet to the respective player.

mutation CreateManagedWallet {
CreateWallet(externalId: "player_1_id") #Replace this with a unique ID
}
Lost database data?

Recreate the Managed wallets by running CreateWallet mutation again for each of the externalIds.
Make sure to use the same Daemon wallet seed and password used to create Managed wallets prior, as Managed wallets are derived with the following derivation path: walletSeed/externalId///password

Interact with Managed Wallets

Once the Managed wallet is created, you can provide the externalId field of the Wallet object to any query or mutation that accepts a Wallet.externalId parameter, in order to use a Managed wallet instead of any other wallet.

Lets look at the GetWallet query as an example, to get the Public Key of an account, we use the account's address. account: "address_here"

However, to get the Public Key of a Managed wallet, we provide the Wallet.externalId parameter instead.

Query:

query GetManagedWalletPublicKey {
GetWallet(externalId: "player_1_id") { #Specify the managed wallet unique ID
account {
address
publicKey
}
}
}

Response:

{
"data": {
"GetWallet": {
"account": {
"address": "cxMkGKAmD73fGoFVaKj5HNmeLRHpTFDf5oQMp2dsqKJ8uZ3tT", //Account address for Managed wallet ID "player_1_id"
"publicKey": "0x92f33d3efd6af37798b125cba08e21fc7b404293f12c067f1cb6ab326775ff08"
}
}
}
}

Minting tokens to Managed wallets

With the acquired Managed wallet address, you can mint tokens directly to the Managed wallet.

mutation BatchMint {
BatchMint(
collectionId: 7154 #Specify the collection ID
recipients: [
{
account: "cxMkGKAmD73fGoFVaKj5HNmeLRHpTFDf5oQMp2dsqKJ8uZ3tT" #The recipient of the mint (the Managed wallet account address from the GetWallet query)
mintParams: {
amount:1 #Amount to mint
tokenId: {integer: 6533} #Token ID to mint
}
}
]
) {
id
method
state
}
}

Transferring tokens from managed wallets

If you followed along the previous snippets of code, you should have a Managed wallet with a token in it. To transfer it out to another wallet, we can use the BatchTransfer mutation.

Signing transactions using a managed wallet

It's important to note that every mutation that accepts a signingAccount argument can be used to sign the transaction using a managed wallet, as shown in the batch transfer tutorial below.

mutation BatchTransfer {
BatchTransfer(
collectionId: 7154 #Specify the collection ID
signingAccount: "cxMkGKAmD73fGoFVaKj5HNmeLRHpTFDf5oQMp2dsqKJ8uZ3tT" # Add your signing account address (the Managed wallet account address from the GetWallet query)
recipients: [
{
account: "cxLf6yvvtscKrHRfKDphnzsT3eoRY45VbJvqXKub5pmj5mdbQ" #The recipient of the transfer
simpleParams: {
tokenId: { integer: 6533 } #Token ID to transfer
amount: 1 #Amount to transfer
}
}
]
) {
id
method
state
}
}

Make sure that signingAccount is set to the Managed Wallet address that owns that token.

Explore More Arguments

For a comprehensive view of all available arguments for queries and mutations, please refer to our API Reference. This resource will guide you on how to use the GraphiQL Playground to explore the full structure and functionality of our API.