Create & send NFT

Deploy contract and send NFT to a user's wallet and check balance

🔭 Guide overview

In this guide you will create a contract and airdrop an ERC1155 token to a user's wallet and then check balance to confirm. The mapping, which describes these tokens are simply

📘

ERC1155: The NFT + FT Token standard

The idea is simple and seeks to create a smart contract interface that can represent and control any number of fungible and non-fungible token types. In this way, the ERC-1155 token can do the same functions as an ERC-20 and ERC-721 token, and even both at the same time. And best of all, improving the functionality of both standards, making it more efficient, and correcting obvious implementation errors on the ERC-20 and ERC-721 standards.

Learn more about the type of token here: Ethereum.org docs on ERC1155 tokens ↗️

🏷️ Use-case examples with the Croak ERC-1155 APIs

  • Create & sell in-game items with limited, multiple copies
  • Create & sell unique collectible items on your platform
  • Create & sell 1/1 digital art
  • Reward progress of a user on your app by evolving an NFT

🧱 Implementation steps

  1. Client creation : Create your client using the Create new client guide ↗️ and use the x-api-key in the further steps
  2. Deploy contract: We need to first deploy a contract, which will hold the ERC1155 tokens. Choose chain mumbai and type OpenGlipERC1155. We will support the others soon.

See the API reference ↗️ for code snippet in multiple languages and more information about the API and its fields (name, symbol, description, ...)

> curl --request POST \
     --url https://be.namasteapis.com/blockchain/v1/contract/create \
     --header 'Accept: application/json' \
     --header 'Content-Type: application/json' \
     --header 'x-api-key: TheCompanyAPIkey' \
     --data '
{
     "name": "SomeName",
     "symbol": "SomeSymbol",
     "description": "SomeDescription",
     "chain": "mumbai",
     "image": "someimageurl.jpeg",
     "externalUrl": "someimageurl.jpeg",
     "type": "OpenGlipERC1155"
}
'

{
  "data": {
    "confirmed": true,
    "id": "62a38b9b08992327f2634b00",
    "name": "SomeName",
    "description": "SomeDescription",
    "chain": "mumbai",
    "image": "someimageurl.jpeg",
    "externalUrl": "someimageurl.jpeg",
    "media": [
      {
        "type": "number",
        "value": "1"
      }
    ],
    "type": "OpenGlipERC1155",
    "contractAddress": "0xe9F3a256Beda25e4a30Cc65C61B108D74791A103",
    "transactionHash": "0x5e3bd8135074fd594582ed70878d1222e53dd9242e1ba60e4d14fe7da7611944",
    "deployer": "0xF1b6fceac6784a26360056973C41e0017DeE12e4",
    "factory": "0x0405aA9fef3986fd56470107D38f2a554E1856fa",
    "creatorId": "62335548760f50d618bc7b35",
    "owner": "0xF1b6fceac6784a26360056973C41e0017DeE12e4",
  },
  "success": true,
  "message": "Contract created"
}

You can try it yourself 😎 here!

  1. Create the token metadata: Before we can send an NFT, we need to create the token metadata. Use the id from the above as your contractDataId. In this case it is 62a38b9b08992327f2634b00 and use the following API, see API Reference ↗️ for more languages snippets. Since, ERC1155 combines both fungible and non-fungible types, just setting the supply to 1 makes the token id a NFT, whereas setting it to any number greater than 1 would make that token id a FT.

📘

Token Metadata - Rich Properties of NFTs

Attributes help attach rich features/properties to the NFTs. They may signify scores, levels, traits, history, evolution of the NFT. Investors factor in attributes while pricing the token while gamers value the attributes because they may unlock features in a game.

Croak allows 2 ways to set metadata - hosted by Croak or self-hosted.

More details in the Guide here ↗️

> curl --request POST \
     --url https://be.namasteapis.com/blockchain/v1/token-data/create \
     --header 'Accept: application/json' \
     --header 'Content-Type: application/json' \
     --header 'x-api-key: TheCompanyAPIkey' \
     --data '
{
     "metadata": {
          "name": "SomeName",
          "description": "SomeDescription",
          "image": "SomeImage.jpeg",
          "external_url": "SomeWebsite.com",
          "animation_url": "SomeVideo.mp4",
          "attributes": "[]"
     },
     "supply": 1,
     "assetContractId": "62a38b9b08992327f2634b00"
}
'
Truncated response
{
  "data": {
    "id": "62a38cb708992327f2634b36",
    "creatorId": "62335548760f50d618bc7b35",
    "type": "ERC1155_LAZY",
    "name": "SomeName",
    "description": "SomeDescription",
    "externalUri": "SomeWebsite.com",
    "imageUri": "SomeImage.jpeg",
    "videoUri": "SomeVideo.mp4",
    "attributes": "[]",
    "supply": 1,
    "reserveTokenDataId": "62a369c43a45893dcf7bae66",
    "reserveTokenDataAmount": 10,
    "assetContractId": "62a38b9b08992327f2634b00",
    "tokenId": "50773715742106732018698306139051929138629421045594680327232414164177859221168",
  },
  "success": true,
  "message": "Token data saved"
}

You can try it yourself 😎 here!

  1. Send token: Pick the id of the metadata from the response above; this is your tokenDataId - 62a38cb708992327f2634b36 in this example. Get the walletId of the user to send the token to, 627cb7ea2cd263018f2adfb7 in this example. Use the api to send the token to any wallet id. See API Reference for code snippets in more languages ↗️
> curl --request POST \
     --url https://be.namasteapis.com/blockchain/v1/airdrop/token-data \
     --header 'Accept: application/json' \
     --header 'Content-Type: application/json' \
     --header 'x-api-key: TheCompanyAPIkey' \
     --data '
{
     "destinations": [
          "627cb7ea2cd263018f2adfb7"
     ],
     "amounts": [
          1
     ],
     "tokenDataId": "62a38cb708992327f2634b36"
}
'


{
  "data": [
    {
      "amount": 1,
      "status": "success",
      "cancelled": false,
      "isClaimed": false,
      "_id": "62a38d5108992327f2634b58",
      "creatorId": "62335548760f50d618bc7b35",
      "tokenDataId": "62a38cb708992327f2634b36",
      "error": "",
      "exchangeContract": "0x3B2A17fd2c4C3Bb968Efa91ae63AAfe8A7c5E69E",
      "mintSaleType": "airdrop",
      "minted": true,
      "mintTxId": "0xef096055f6f59bead13bb247701b2af22ec86b3acf37e058c46c5683775d705b",
      "mintTxStatus": "done",
      "mintedAt": "2022-06-10T18:28:33.190Z",
      "mintedPrice": "0",
      "mintedCurrency": "USD",
      "mintedTo": "0x8E8132a63EeD858CB8ABB3b7D0Bd3c4DF9E1B6bd",
      "walletId": "627cb7ea2cd263018f2adfb7",
      "id": "62a38d5108992327f2634b58"
    }
  ],
  "success": true,
  "message": "Token minting started"
}

You can try it yourself 😎 here!

  1. Check balance: Get your NFT token balance using the following API. See API Reference for code snippets in more languages ↗️
> curl --request GET \
     --url 'https://be.namasteapis.com/blockchain/v1/wallet-balance/list-wallet-nft-server?walletId=627cb7ea2cd263018f2adfb7&tokenDataIds=62a38cb708992327f2634b36&size=50' \
     --header 'Accept: application/json' \
     --header 'x-api-key: Your API Key'

{
  "data": {
  	"nfts": [
      {
        "token": {
          "id": "62de5075908167125627763f",
          "creatorId": "62de50119081671256277626",
          "type": "ERC1155_LAZY",
          "name": "SomeName",
          ...
          "tokenId": "99114679086191728320366730639322510063936417164752678688100933618617724390488"
        },
        "quantity": "1"
      }
    ],
    "contracts": [
      {
        "confirmed": true,
        "id": "62de504e9081671256277637",
        "name": "Test",
        ...
        "type": "OpenGlipERC1155",
        "contractAddress": "0x6608F7D00C3334Dc7FeF8515c00dEc23C3F02551"
      }
    ]
    "lastId": "62de5075908167125627763f"
  },
  "success": true,
  "message": "Users nft data"
}

You can try it yourself 😎 here!

  1. That's it you're done 🏁

📌 Further queries

For any queries or guidance, join https://croak.discord.com or write to [email protected]