DAN
Website
  • 🚀Accelerating Digital Ownership Adoption
  • Digital Assets Network
    • ❌Challenges in Adoption
    • ✅DAN Stack
    • 📜Modular Protocol
    • 🎯DAN Labs Impact
    • 🔐®️ ERC-7066 Author
      • Overview
  • DAN PROTOCOLS
    • 📌Modular Solutions for Digital Ownership
    • 💡Asset Creation
    • 🤝Marketplace
    • 🔓Rent Protocol
    • 💰Loan Protocol
      • How does a loan work?
    • 💰Utility Protocol
      • How does it work?
  • For Developers
    • 🚀Launchpad
      • APIs
        • User's Collections
        • Collection Details
      • SDK
        • Create Collection
        • Mint NFT
        • Mint NFT (Batch)
    • 🛒Market
      • APIs
      • SDK
        • Create Listing
        • Buy Listed NFT
        • Cancel Listing
    • ⚙️Utility
      • APIs
        • 👥Client
          • Register
          • Verify
          • Redeem Code
          • Get All Claimed Utility User
        • 👨‍💻Developer
          • Get All Benefits By Collection
      • SDK
    • 💰Loans
      • APIs
        • User Loans
        • Raw Transactions (Advanced)
      • SDK
        • EVM
        • Solana
      • Wallet Integration
        • EVM
        • Solana
    • 🗞️Rentals
      • APIs
        • NFTs (Owned and Rented)
        • NFTs (Rented)
        • Raw Transactions (Advanced)
      • On-Chain
      • SDK
        • EVM
        • Solana
      • Wallet Integration
        • EVM
        • Solana
    • ⛓️Supported Chains
  • UseCases : Case Studies
    • 🤝NFT Rentals
    • 💎Ephemeral / Consumable NFTs
    • 📝NFT Mandates
    • 🎆Post-Mint Utility
    • 💼Partial Payment at Mint
  • Community
    • 🔑Terms of Service
    • 🔏Privacy Policy
    • 🌐Website
    • 👽Discord
    • 🐦Twitter
Powered by GitBook
On this page
  1. For Developers
  2. Utility

SDK

PreviousGet All Benefits By CollectionNextLoans

Last updated 2 months ago

To integrate the SDK with your repository, follow the steps below. The following code snippets provide examples of how to use the SDK functions to interact with the smart contract.

Testnet SDK: Mainnet SDK: streamnft-evm (TBA)

const stream = require('streamnft-utility');

//for browser wallets
signer = stream.getWalletSigner();  

//for signer using private key  
signer= stream.getSigner(chainId, privateKey, rpcUrl);    

1. Create Utility Create Utility on any NFT collection

  • create utility schema with UtilitySchema

UtilitySchema
{
  "utilityId": {
    "type": "String",
    "required": true,
    "unique": true
  },
  "utilityIndex": "Number",
  "provider": "String",
  "winners": [
    "String"
  ],
  "participants": [
    "String"
  ],
  "chainId": "Number",
  "utilityType": {
    "type": "String",
    "required": true
  },
  "usage": {
    "expiryOrUsage": "Number",
    "startOnClaim": "Boolean"
  },
  "raffle": {
    "totalEntries": {
      "type": "Number",
      "default": 0
    },
    "participants": [
      "String"
    ],
    "winners": [
      "String"
    ],
    "maxEntries": "Number",
    "winnersMerkle": "String",
    "claimDate": "Date"
  },
  "target": [
    {
      "collection": "String",
      "chainId": "String",
      "name": "String",
      "eligibleType": {
        "type": "String",
        "required": true
      },
      "traits": [
        {
          "key": "String",
          "value": "String"
        }
      ]
    }
  ],
  "eligible": {
    "type": "Map",
    "of": {
      "eligibleType": {
        "type": "String",
        "required": true
      },
      "participants": [
        "String"
      ],
      "externalService": {
        "type": "String"
      },
      "traits": [
        {
          "key": "String",
          "value": "String"
        }
      ],
      "numberOfEntries": "Number",
      "collectionImage": "String",
      "collectionName": "String",
      "chainId": "String",
      "collectionAddress": "String",
      "taskDetails": [
        {
          "taskInfo": "String",
          "serviceTarget": "String",
          "targetURL": "String",
          "numberOfEntries": "Number",
          "mandatory": "Boolean"
        }
      ]
    },
    "default": {}
  },
  "partner": "String",
  "selectionType": {
    "type": "String",
    "required": true
  },
  "title": "String",
  "category": "String",
  "image_url": "String",
  "reward": {
    "value": "String",
    "estimatedValue": "String",
    "mintPrice": "Number",
    "details": [
      "String"
    ],
    "image": "String",
    "type": {
      "type": "String",
      "required": true
    },
    "currency": {
      "type": "String",
      "default": "USD"
    },
    "count": "Number",
    "expiry": "String",
    "chainId": "Number",
    "secret": {
      "value": "String",
      "details": [
        {
          "value": "String",
          "claimed": "Boolean"
        }
      ]
    },
    "congratulationText": "String"
  },
  "createdAt": "Date",
  "description": "String",
  "startDate": "Date",
  "endDate": "Date"
}
const stream = require('streamnft-utility');

stream.createUtility(utility, chainId, signer)
  .then((result) => {
    // Handle the result
  })
  .catch((error) => {
    // Handle the error
  });

This shall return index of utility created: utilityId

{success:true, data: <index> (int)}
  1. Get All Utility By Collection

Get Utilities present on a collection

const stream = require('streamnft-utility');

stream.getAllUtilityByCollection(collectionAddress)
  .then((result) => {
    // Handle the result
  })
  .catch((error) => {
    // Handle the error
  });
  1. Get All Utility By User

Get all Utilities accessible to a wallet

const stream = require('streamnft-utility');

stream.getAllUtilityByUser(wallet, chainId)
  .then((result) => {
    // Handle the result
  })
  .catch((error) => {
    // Handle the error
  });
  1. Join Raffle

Join Raffle Type Utility

const stream = require('streamnft-utility');

stream.joinRaffle(chainId, utilityId, signer)
  .then((result) => {
    // Handle the result
  })
  .catch((error) => {
    // Handle the error
  });
  1. Claim Reward

Claim reward for giveaways utilities

const stream = require('streamnft-utility');

stream.claimReward(chainId, utilityId, user, proof, signer)
  .then((result) => {
    // Handle the result
  })
  .catch((error) => {
    // Handle the error
  });
  1. Claim Utility On NFT

Claim NFT benefit utility

const stream = require('streamnft-utility');

stream.claimUtilityOnNFT(user, tokenId, utilityId, proof, chainId,signer)
  .then((result) => {
    // Handle the result
  })
  .catch((error) => {
    // Handle the error
  });
  1. Redeem Utility On NFT

Redeem NFT benefit utility

const stream = require('streamnft-utility');

stream.redeemUtilityOnNFT(tokenId, utilityId, chainId,signer)
  .then((result) => {
    // Handle the result
  })
  .catch((error) => {
    // Handle the error
  });
  1. Check NFT utility

Check if NFT is valid for any utility

const stream = require('streamnft-utility');

stream.checkNFTUtility(tokenId, utilityId, chainId, provider)
  .then((result) => {
    // Handle the result
  })
  .catch((error) => {
    // Handle the error
  });
⚙️
streamnft-utility-test