Managing Tokens
10

Once your tokens have been minted, you may want to edit, send, or melt them down and recover the Enjin Coin (ENJ) from within inside the tokens.

The Platform API has been built to provide all the functionality you need to manage a robust blockchain-based gaming economy.

You will likely use the following queries and mutations quite often when it comes to managing your tokenized assets.

Change Token Name

Tokens have their names specified on the blockchain and within their metadata.

This means tokens can, technically, be given a different name on the blockchain and in its metadata.

This following mutation can be used to update a token's name on the blockchain:

GraphQL
mutation UpdateTokenName($identityId: Int!, $itemNameData: UpdateItemNameInput!) {
 CreateEnjinRequest(identity_id: $identityId, type: UPDATE_NAME, update_item_name_data: $itemNameData) {
   id
   encodedData
 }
}

Melt Batch Items

There may be times that you make a mistake during the token minting process and you wish to melt all of the tokens you have created.

To melt any token, the token must be in your wallet. It's important to quadruple check your token settings prior to sending them to your users.

Once your tokens have been distributed to your users, there is no going back and the only way to fix any errors is to generate replacement tokens.

GraphQL

mutation BatchMelt($identityId: Int!, $meltTokenData: MeltTokenInput!) {
 CreateEnjinRequest(identity_id: $identityId, type: MELT, melt_token_data: $meltTokenData) {
   identityId
   tokenId
 }
}

Release Reserve

When you first create a token, you will be asked to lock an initial reserve on the Enjin Coin (ENJ) into it.

This is to ensure you can mint your tokens fluidly, using the Enjin Coin you have set aside.

If you no longer wish to use the token, and decide not to go ahead with minting the respective tokens, you can destroy the template and return the Enjin Coin that you have set aside by using the following mutation:

GraphQL
mutation ReleaseReserve($identityId: Int!, $tokenId: String!, $value: Int!) {
 CreateEnjinRequest(identity_id: $identityId, type: RELEASE_RESERVE, release_reserve_data: {token_id: $tokenId, value: $value}) {
   tokenId
 }
}

Note: There is a cool down period for releasing reserve and the more Enjin Coin you have locked into the template, the longer you have to wait until you can release it. This waiting period can take days or even weeks.

Send All Item Types: Advanced Send

The Platform API allows you to send unlimited Fungible and up to 100 Non-Fungible tokens to up to 1000 users, in a single transaction.
The Advanced Send mutation is one of the most common mutations to send vast amounts of assets from one address, to another in a single transaction and with ease.

This is the most robust and popular sending mutation used by developers:

GraphQL
mutation AdvancedSend($identityId: Int!, $tokenData: AdvancedSendTokenInput!) {
 CreateEnjinRequest(identity_id: $identityId, type: ADVANCED_SEND, advanced_send_token_data: $tokenData) {
   id
   encodedData
 }
}

Transfer Whitelisting

If you've created a bound token or a token with transfer fees, and you don't wish for these settings to apply in every circumstance, you can use transfer whitelisting to allow specific users to send tokens to specific addresses.

GraphQL
mutation WhitelistToken($identityId: Int!, $appId: Int!, $whitelistData: SetWhitelistedInput!) {
 CreateEnjinRequest(identityId: $identityId, appId: $appId, type: SET_WHITELISTED, set_whitelisted_data: $whitelistData) {
   id
   encodedData
 }
}

Whitelist Settings

Full Rights: The address has full rights to send and receive the token.
<inline-code>0x0000000000000000000000000000000000000001<inline-code>

Can Send: The address can send but not receive the token. Which means the only way they can get the token, is if you mint it directly to their address.
<inline-code>0x0000000000000000000000000000000000000002<inline-code>

Can Receive: The address can receive but can't send the token.
<inline-code>0x0000000000000000000000000000000000000003<inline-code>

No Fees: The address can send tokens without paying transfer fees.
<inline-code>0x0000000000000000000000000000000000000004<inline-code>

Token Details

If you wish to provide your users detailed information about a specific token, you can use this query to lookup the data:

GraphQL
query GetTokenDetails($name: String!) {
 EnjinTokens(name: $name, pagination: {page: 1, limit: 50}) {
   id
   name
   creator
   meltValue
   meltFeeRatio
   meltFeeMaxRatio
   supplyModel
   totalSupply
   circulatingSupply
   reserve
   transferable
   nonFungible
   blockHeight
   markedForDelete
   createdAt
   updatedAt
   availableToMint
   itemURI
 }
}

Token Holders

This query returns a list of addresses who own a specific token:

GraphQL
query GetBalance($tokenId: String!) {
 EnjinBalances(tokenId: $tokenId) {
   token {
     id
     index
   }
   wallet {
     ethAddress
   }
   value
 }
}

It can be useful for rewarding all holders of a specific token in one go, through a coordinated airdrop.

Transaction Data

Whenever you issue a send mutation, an id will be returned to you. This id is very important and it is highly advisable to log this data so you can access it again, at a later date.

Should you want to view the state of any transaction that you have performed on the blockchain, you will need to use this query:

GraphQL
query GetTransaction($id: Int!) {
 EnjinTransactions(id: $id) {
   id
   transactionId
   type
   state
   error
   token {
     id
     name
   }
 }
}

The Enjin Transactions query will return vvarious pieces of information, depending on the state of the transaction that you have ran.
You will notice that we added the error argument within the query. The error argument is useful to have, in case your transaction has failed / dropped for a certain reason, this will display why the transaction in question did not process on the blockchain.

This query will return the following values:

  • PENDING: Transaction is created on the Enjiin Cloud, but has not yet been signed by the user/dev.
  • TP_PROCESSING: Transaction has been signed and is waiting for the Enjin Cloud/Platform) to process the transaction for broadcast.
  • BROADCAST: Transaction has been signed and has been broadcast but has not yet been confirmed on the blockchain.
  • EXECUTED: The transaction has received confirmation on the blockchain and the Enjin Cloud.
  • CANCELED_USER: The user has canceled the PENDING transaction/not signed.
  • CANCELED_PLATFORM: The Platform has canceled the PENDING transaction.
  • FAILED: Transaction has failed on the Enjiin Platform.
  • DROPPED: Transaction was not mined on the blockchain and has since been dropped.

Set Spending Allowance

If you want to increase the security of your project and set a spending limit for yourself, or allow your players to choose their own spending limited, you can use this mutation to set a spending allowance:

GraphQL
mutation ApproveEnj($id: String!, $limit: Int!) {
 CreateEnjinRequest(identity_id: $id, type: APPROVE, approve_enj_data: {value: $limit}) {
   id
 }
}

Set value as -1 for max value.

Note: This value decreases as it is used, like a literal spending allowance. If you set the value to 10 Enjin Coin (ENJ) and then make 10 transactions for 1 ENJ each, your allowance will go down to 0 and it will need to be set again.

Trade Request

Initiating secure peer-to-peer trades is a three-step process. The way this works is, first, the trade needs to be created, the respective items need to be held in escrow, and once both parties have checked the items, they can complete the trade.

Step 1: Create the trade request and confirm in 1st person's wallet.

GraphQL
mutation SendTradeRequest($initiatorId: Int!, $recipientId: Int!) {
 CreateEnjinRequest(identity_id: $initiatorId, type: CREATE_TRADE, create_trade_data: {asking_tokens: [{id: "XXXXXXXXXXXXXXXXX", value: 1}], offering_tokens: [{id: "XXXXXXXXXXXXXXXXX", value: 1}], second_party_identity_id: $recipientId}) {
   id
   encodedData
   state
 }
}

Use the id: "0" argument for Enjin Coin (ENJ).

Step 2: Get the trade_id - param1.

GraphQL
query RetrieveTradeId($id: Int!) {
 EnjinTransactions(id: $id) {
   type
   transactionId
   events {
     param1
   }
 }
}

Step 3: Complete the trade request. Enter param1 as trade_id, 2nd persons identity_id and confirm in 2nd persons wallet.

GraphQL
mutation CompleteTradeRequest($id: Int!, $tradeId: String!) {
 CreateEnjinRequest(identity_id: $id, type: COMPLETE_TRADE, complete_trade_data: {trade_id: $tradeId}) {
   id
   transactionId
   encodedData
 }
}

Changing Asset Transfer Status

At times, you may want to change the transfer status of a token you have created to give it certain value, whether you want the token to be permanently transferable, temporary transferable or bound to an address.

Note: If you have set the token to be permanently transferable, you will not be able to alter that setting.

GraphQL
mutation ChangeAssetTransferableType($appId: Int!, $identityId: Int!, $tokenId: String!, $transferable: TokenTransferable!) {
 CreateEnjinRequest(appId: $appId, identityId: $identityId, type: SET_TRANSFERABLE, set_transferable_data: {token_id: $tokenId, transferable: $transferable}) {
   id
   encodedData
 }
}

Blockchain Explorer

Players are inherently interested in the blockchain data behind the assets they own.

If you would like to link your users to the EnjinX listing of a specific token, you can append the token ID to the end of the URL. This allows them to learn everything they can about their tokens.

Example:

https://jumpnet.enjinx.io/eth/asset/000000000000000

https://enjinx.io/eth/asset/000000000000000

Previous
next
On This Page