Skip to main content

SDK methods

Let’s assume that the address of the player’s wallet is stored in a static class called “playerData” and that all the methods are called in a script name ApiHandler.cs that will only handle the calls to the API.

The start of the script will look like this:

ApiHandler.cs
public class ApiHandler
{
private string walletAddress;
private GamingApi gamingApi;

private void Start()
{
walletAddress = playerData.walletAddress;
gamingApi = new GamingApi();
}
}

Now that we have the base of the script defined, let's see how we can implement each method of the GamingAPI class.


Balance Of

With this method, you will be able to know how many of a specific NFT owns the player.

To implement it, you should create an IEnumerator which receives:

  • Contract:
    • Type: String
    • Description: The ID of the contract of the NFT
  • Network:
    • Type: String
    • Description: The ID of the network, in decimal format, of the NFT
  • Address:
    • Type: String
    • Description: The wallet address of the wallet where you want to see the balance of the NFT
  • Id:
    • Type: String
    • Description: The ID of the NFT to get his balance

Inside this IEnumerator you should create a variable of type int. Here is where the balance will get stored once the API returns the amount of NFTs.

Then you should start the coroutine "BalanceOf" inside the "gamingApi" class, with the yield return statement, and with a delegate that will set the balance that the API returns as the value of the previously created variable, and all the values received on the IEnumerator, in the following order:

  1. Contract
  2. Network
  3. Address
  4. Id

Here is an example of how it should be implemented to print on the console the ammount of a specific NFT that the player has in his wallet:

public void CallBalanceOf()
{
StartCoroutine(BalanceOf("contractAddress", "networkId", walletAddress, "nftId"));
}

private IEnumerator BalanceOf(string contractAddress, string networkId, string walletAaddress, string nftId)
{
int resultBalance = 0;

yield return StartCoroutine(gamingApi.BalanceOfNft(balance => resultBalance = balance, contractAddress, networkId, walletAaddress, nftId));

OnBalanceRecived(resultBalance);
}

private void OnBalanceRecived(int balance)
{
// Apply your desired logic here
Debug.Log($"The player has {balance} of this NFT");
}

Token URI

With this method, you will be able to get the URI of a specific NFT.

To implement it, you should create an IEnumerator which receives:

  • Contract:
    • Type: String
    • Description: The ID of the contract of the NFT
  • Network:
    • Type: String
    • Description: The ID of the network, in decimal format, of the NFT
  • Id:
    • Type: String
    • Description: The ID of the NFT to get his balance

Inside this IEnumerator you should create a variable of type string. Here is where the URI of the NFT will get stored once the API returns the URI.

Then you should start the coroutine "TokenUri" inside the "gamingApi" class, with the yield return statement, and with a delegate that will set the URI that the API returns as the value of the previously created variable, and all the values received on the IEnumerator, in the following order:

  1. Contract
  2. Network
  3. Id

Here is an example of how it should be implemented to print on the console the URI of a specific NFT:

private void callTokenUri()
{
StartCoroutine(TokenUri("contractAddress", "networkId", "nftId"));
}

IEnumerator TokenUri(string contractAddress, string networkId, string nftId)
{
string resultUri = "";

yield return StartCoroutine(gamingApi.TokenUri(uri => resultUri = uri, contractAddress, networkId, nftId));

OnTokenUriRecived(resultUri);
}

private void OnTokenUriRecived(string uri)
{
// Apply your desired logic here
Debug.Log(uri);
}

Mint

With this method, you will be able to mint one NFT.

To implement it, you should create an IEnumerator which receives:

  • Contract:
    • Type: String
    • Description: The ID of the contract of the NFT
  • Network:
    • Type: Int
    • Description: The ID of the network, in decimal format, of the NFT
  • WalletAddress:
    • Type: String
    • Description: The address of the wallet where the NFT will be minted
  • Amount:
    • Type: Int
    • Description: The amount of copies of the NFT that will be minted
  • Uri:
    • Type: String
    • Description: The URI of the metadata of the NFT

Inside this IEnumerator you should create two variables of type string. Here is where the transaction hash and the **transaction nonce ** of the mint operation will get stored once the API mint the NFT.

Then you should start the coroutine "Mint" inside the "gamingApi" class, with the yield return statement, and with two delegates that will set the transaction hash and the transaction nonce that the API returns as the values of the previously created variables, and all the values received on the IEnumerator, in the following order:

  1. Contract
  2. Network
  3. WalletAddress
  4. Amount
  5. Uri

Here is an example of how it should be implemented to mint the NFT on the player's wallet and print on the console the transaction hash and the transaction nonce of the mint operation once is completed:

private void CallMint()
{
StartCoroutine(Mint("contractAddress", 0, "walletAddress", 5, "nftUri"));
}

IEnumerator Mint(string contractAddress, int networkId, string walletAddress, int amount, string metadataUri)
{
string responseTxHash = "";
string responseNonce = "";

yield return StartCoroutine(gamingApi.Mint(hash => responseTxHash = hash, nonce => responseNonce = nonce, contractAddress, networkId, walletAddress, amount, metadataUri));

OnNftMinted(responseTxHash, responseNonce);
}

private void OnNftMinted(string txHash, string nonce)
{
// Apply your desired logic here
Debug.Log($"ID: {txHash} - Network: {nonce}");
}

Mint Batch

With this method, you will be able to mint multiple NFTs at once.

To implement it, you should create an IEnumerator which receives:

  • Contract:
    • Type: String
    • Description: The ID of the contract of the NFTs
  • Network:
    • Type: Int
    • Description: The ID of the network, in decimal format, of the NFTs
  • WalletAddress:
    • Type: String
    • Description: The address of the wallet where the NFTs will be minted
  • Amounts:
    • Type: Int Array
    • Description: Array with the amounts of copies of each NFT that will be minted
  • Uris:
    • Type: String Array
    • Description: Array with the URIs of the metadata of each NFT

Inside this IEnumerator you should create two variables of type string. Here is where the transaction hash and the **transaction nonce ** of the mint operation will get stored once the API mint all the NFTs.

Then you should start the coroutine "MintBatch" inside the "gamingApi" class, with the yield return statement, and with two delegates that will set the transaction hash and the transaction nonce that the API returns as the values of the previously created variables, and all the values received on the IEnumerator, in the following order:

  1. Contract
  2. Network
  3. WalletAddress
  4. Amounts
  5. Uris

Here is an example of how it should be implemented to mint the NFTs on the player's wallet and print on the console the transaction hash and the transaction nonce of the mint operation once is completed:

private void CallMintBatch()
{
int[] ammounts = {3, 5};
string[] uris = {"firstNftUri", "secondNftUri};
StartCoroutine(MintBatch("contractAddress", 0, walletAddress, ammounts, uris));
}

IEnumerator MintBatch(string contractAddress, int networkId, string walletAddress, int[] amounts, string[] metadataUris)
{
string responseTxHash = "";
string responseNonce = "";

yield return StartCoroutine(gamingApi.MintBatch(hash => responseTxHash = hash, nonce => responseNonce = nonce, contractAddress, networkId, walletAddress, amounts, metadataUris));

OnMultipleNftsMinted(responseTxHash, responseNonce);
}

private void OnMultipleNftsMinted(string txHash, string nonce)
{
// Apply your desired logic here
Debug.Log($"ID: {txHash} - Network: {nonce}");
}

Transfer

With this method, you will be able to transfer one NFT from one wallet to another.

To implement it, you should create an IEnumerator which receives:

  • Contract:
    • Type: String
    • Description: The ID of the contract of the NFT
  • Network:
    • Type: Int
    • Description: The ID of the network, in decimal format, of the NFT
  • OriginWalletAddres:
    • Type: String
    • Description: The address of the wallet from where the NFT will be transferred
  • DestinationWalletAddress:
    • Type: String
    • Description: The address of the wallet where the NFT will be transferred
  • Id:
    • Type: Int
    • Description: The ID of the NFT that will be transferred
  • Amount:
    • Type: Int
    • Description: The amount of the same NFT that will be transferred

Inside this IEnumerator you should create two variables of type string. Here is where the transaction hash and the **transaction nonce ** of the transfer operation will get stored once the API transfers the NFT.

Then you should start the coroutine "Transfer" inside the "gamingApi" class, with the yield return statement, and with two delegates that will set the transaction hash and the transaction nonce that the API returns as the values of the previously created variables, and all the values received on the IEnumerator, in the following order:

  1. Contract
  2. Network
  3. OriginWalletAddress
  4. DestinationWalletAddress
  5. Id
  6. Amount

Here is an example of how it should be implemented to transfer 5 copies of an NFT from the project wallet to the player's wallet and print on the console the transaction hash and the transaction nonce of the transfer operation once is completed:

private void CallTransfer()
{
int[] ammounts = {3, 5};
string[] uris = {"firstNftUri", "secondNftUri};
StartCoroutine(Transfer("contractAddress", 0, "projectWalletAddress", walletAddress, 0, 5));
}

IEnumerator Transfer(string contractAddress, int networkId, string originWalletAddress, string destinationWalletAddress, int nftId, int amount)
{
string responseTxHash = "";
string responseNonce = "";

yield return StartCoroutine(gamingApi.Transfer(hash => responseTxHash = hash, nonce => responseNonce = nonce, contractAddress, networkId, originWalletAddress, destinationWalletAddress, nftId, amount));

OnNftTransferred(responseTxHash, responseNonce);
}

private void OnNftTransferred(string txHash, string nonce)
{
// Apply your desired logic here
Debug.Log($"ID: {txHash} - Network: {nonce}");
}

Transfer Batch

With this method, you will be able to transfer multiple NFTs from one wallet to another.

To implement it, you should create an IEnumerator which receives:

  • Contract:
    • Type: String
    • Description: The ID of the contract of the NFT
  • Network:
    • Type: Int
    • Description: The ID of the network, in decimal format, of the NFT
  • OriginWalletAddres:
    • Type: String
    • Description: The address of the wallet from where the NFT will be transferred
  • DestinationWalletAddress:
    • Type: String
    • Description: The address of the wallet where the NFT will be transferred
  • Ids:
    • Type: Int Array
    • Description: The IDs of the NFTs that will be transferred
  • Amounts:
    • Type: Int Array
    • Description: The amounts of the NFTs that will be transferred

Inside this IEnumerator you should create two variables of type string. Here is where the transaction hash and the **transaction nonce ** of the transfer batch operation will get stored once the API transfers the NFTs.

Then you should start the coroutine "TransferBatch" inside the "gamingApi" class, with the yield return statement, and with two delegates that will set the transaction hash and the transaction nonce that the API returns as the values of the previously created variables, and all the values received on the IEnumerator, in the following order:

  1. Contract
  2. Network
  3. OriginWalletAddress
  4. DestinationWalletAddress
  5. Ids
  6. Amounts

Here is an example of how it should be implemented to transfer 3 copies of one NFT and 5 copies of another NFT from the project wallet to the player's wallet and print on the console the transaction hash and the transaction nonce of the transfer batch operation once is completed:

private void CallTransferBatch()
{
int[] ids = {0, 1};
string[] amounts = {3, 5};
StartCoroutine(TransferBatch("contractAddress", 0, "projectWalletAddress", walletAddress, ids, ammounts));
}

IEnumerator TransferBatch(string contractAddress, int networkId, string originWalletAddress, string destinationWalletAddress, int[] nftIds, int[] amounts)
{
string responseTxHash = "";
string responseNonce = "";

yield return StartCoroutine(gamingApi.TransferBatch(hash => responseTxHash = hash, nonce => responseNonce = nonce, contractAddress, networkId, originWalletAddress, destinationWalletAddress, nftIds, amounts));

OnMultipleNftsTransferred(responseTxHash, responseNonce);
}

private void OnMultipleNftsTransferred(string txHash, string nonce)
{
// Apply your desired logic here
Debug.Log($"ID: {txHash} - Network: {nonce}");
}

Upload File

With this method, you will be able to upload a file to use it as NFT.

To implement it, you should create an IEnumerator which receives:

  • Path:
    • Type: String
    • Description: The path to the file to upload
  • Filename:
    • Type: String
    • Description: The name of the file to upload

Inside this IEnumerator you should create a variable of type string. Here is where the hash of the upload operation will get stored once the API uploads the file.

Then you should start the coroutine "UploadFile" inside the "gamingApi" class, with the yield return statement, and with a delegate that will set the hash that the API returns as the value of the previously created variable, and all the values received on the IEnumerator, in the following order:

  1. Path
  2. Filename

Here is an example of how it should be implemented to upload a file and print on the console the hash of the upload operation once is completed:

private void CallUploadFile()
{
StartCoroutine(UploadFile("filePath", "fileName"));
}

IEnumerator UploadFile(string filePath, string fileName)
{
string resultHash = "";

yield return StartCoroutine(gamingApi.UploadFile(hash => resultHash = hash, filePath, fileName));

OnFileUploaded(resultHash);
}

private void OnFileUploaded(string hash)
{
// Apply your desired logic here
Debug.Log(hash);
}

Upload Basic Metadata

With this method, you will be able to upload metadata with basic attributes to create your basic NFT.

To implement it, you should create an IEnumerator which receives:

  • Name:
    • Type: String
    • Description: The name of the NFT
  • File:
    • Type: String
    • Description: The URI of the file that will be the NFT
  • Description:
    • Type: String
    • Description: The description of the NFT

Inside this IEnumerator you should create a variable of type string. Here is where the hash of the upload operation will get stored once the API uploads the metadata.

Then you should start the coroutine "UploadBasicMetadata" inside the "gamingApi" class, with the yield return statement, and with a delegate that will set the hash that the API returns as the value of the previously created variable, and all the values received on the IEnumerator, in the following order:

  1. Name
  2. File
  3. Description

Here is an example of how it should be implemented to upload a metadata and print on the console the hash of the upload operation once is completed:

private void CallUploadBasicMetadata()
{
StartCoroutine(UploadBasicMetadata("nftName", "nftFileUri", "nftDescription"));
}

IEnumerator UploadBasicMetadata(string nftName, string nftFileUri, string nftDescription)
{
string resultHash = "";

yield return StartCoroutine(gamingApi.UploadBasicMetadata(hash => resultHash = hash, nftName, nftFileUri, nftDescription));

OnBasicMetadataUploaded(resultHash);
}

private void OnBasicMetadataUploaded(string hash)
{
// Apply your desired logic here
Debug.Log(hash);
}

Upload Metadata With Numeric Attributes

With this method, you will be able to upload metadata with numeric attributes to create your NFT with numeric attributes based on the Open Sea Metadata Standard.

To implement it, you should create an IEnumerator which receives:

  • Name:
    • Type: String
    • Description: The name of the NFT
  • File:
    • Type: String
    • Description: The URI of the file that will be the NFT
  • Description:
    • Type: String
    • Description: The description of the NFT
  • attributes:
    • Type: NumericAttribute[]
    • Description: Array of NumericAttribute objects, where each element will be a numeric trait of the NFT

The class "NumericAttribute" is a custom class which represents a numeric trait of an NFT based on the Open Sea Metadata Standard and it has the following properties:

  • Display_type:
    • Type: String
    • Description: Type of display on Open Sea
  • Trait_type:
    • Type: String
    • Description: The name of the trait of the NFT
  • Value:
    • Type: Float
    • Description: The numeric value of the trait of the NFT
  • Max_value:
    • Type: Float
    • Description: The maximum value that this attribute can have

You can create an object of this class like this:

//With max value
NumericAttribute numericAttribute = new NumericAttribute("displayType", "traitType", 5, 10)

//Without max value
NumericAttribute numericAttribute = new NumericAttribute("displayType", "traitType", 5)

Inside this IEnumerator you should create a variable of type string. Here is where the hash of the upload operation will get stored once the API uploads the metadata.

Then you should start the coroutine "UploadMetadataWithNumericAttributes" inside the "gamingApi" class, with the yield return statement, and with a delegate that will set the hash that the API returns as the value of the previously created variable, and all the values received on the IEnumerator, in the following order:

  1. Name
  2. File
  3. Description
  4. Attributes

Here is an example of how it should be implemented to upload a metadata and print on the console the hash of the upload operation once is completed:

private void CallUploadMetadataWithNumericAttributes()
{
NumericAttribute[] attributes = {
new NumericAttribute("displayType", "firstTrait", 5, 10),
new NumericAttribute("displayType", "secondTrait", 7)
};
StartCoroutine(UploadMetadataWithNumericAttributes("nftName", "nftFileUri", "nftDescription", attributes));
}

IEnumerator UploadMetadataWithNumericAttributes(string nftName, string nftFileUri, string nftDescription, NumericAttribute[] nftAttributes)
{
string resultHash = "";

yield return StartCoroutine(gamingApi.UploadMetadataWithNumericAttributes(hash => resultHash = hash, nftName, nftFileUri, nftDescription, nftAttributes));

OnMetadataWithNumericAttributesUploaded(resultHash);
}

private void OnMetadataWithNumericAttributesUploaded(string hash)
{
// Apply your desired logic here
Debug.Log(hash);
}

Upload Metadata With Text Attributes

With this method, you will be able to upload metadata with text attributes to create your NFT with text attributes based on the Open Sea Metadata Standard.

To implement it, you should create an IEnumerator which receives:

  • Name:
    • Type: String
    • Description: The name of the NFT
  • File:
    • Type: String
    • Description: The URI of the file that will be the NFT
  • Description:
    • Type: String
    • Description: The description of the NFT
  • attributes:
    • Type: TextAttribute[]
    • Description: Array of TextAttribute objects, where each element will be a text trait of the NFT

The class "TextAttribute" is a custom class which represents a text trait of an NFT based on the Open Sea Metadata Standard and it has the following properties:

  • Trait_type:
    • Type: String
    • Description: The name of the trait of the NFT
  • Value:
    • Type: String
    • Description: The text value of the trait of the NFT

You can create an object of this class like this:

TextAttribute textAttribute = new TextAttribute("traitType", "traitValue")

Inside this IEnumerator you should create a variable of type string. Here is where the hash of the upload operation will get stored once the API uploads the metadata.

Then you should start the coroutine "UploadMetadataWithTextAttributes" inside the "gamingApi" class, with the yield return statement, and with a delegate that will set the hash that the API returns as the value of the previously created variable, and all the values received on the IEnumerator, in the following order:

  1. Name
  2. File
  3. Description
  4. Attributes

Here is an example of how it should be implemented to upload a metadata and print on the console the hash of the upload operation once is completed:

private void CallUploadMetadataWithTextAttributes()
{
TextAttribute[] attributes = {
new TextAttribute("firstTrait", "firstTraitValue"),
new TextAttribute("secondTrait", "secondTraitValue")
};
StartCoroutine(UploadMetadataWithTextAttributes("nftName", "nftFileUri", "nftDescription", attributes));
}

IEnumerator UploadMetadataWithTextAttributes(string name, string fileUri, string description, TextAttribute[] attributes)
{
string resultHash = "";

yield return StartCoroutine(gamingApi.UploadMetadataWithTextAttributes(hash => resultHash = hash, name, fileUri, description, attributes));

OnMetadataWithTextAttributesUploaded(resultHash);
}

private void OnMetadataWithTextAttributesUploaded(string hash)
{
// Apply your desired logic here
Debug.Log(hash);
}

Prepare Message

With this method, you will be able to encrypt a message to be able to send it to the player’s wallet for sign the Web3 Login

info

This method is already implemented in the wallet connection process and you shouldn’t need to use it


Validate Message

With this method, you will be able to check if a message previously prepared with the Prepare Message method has been signed by the player’s wallet, or if it is an impersonation.

info

This method is already implemented in the wallet connection process and you shouldn’t need to use it