StreamNFT
Home
  • 👋Taking NFT mainStream!
  • Introduction
    • 👨‍💻StreamNFT Protocol
    • 🏃Roadmap
    • 🔐Security Audit
  • StreamNFT PROTOCOL
    • 🔓Rent Protocol
    • 💰Loan Protocol
      • How does a loan work?
    • 💰Utility Protocol
      • How does it work?
    • 🎮Web3 Gaming Services
      • Matchmaking
        • Token Gated Matchmaking
    • ®️ERC-7066
      • Overview
  • UseCases : Case Studies
    • 🤝NFT Rentals
    • 💎Ephemeral / Consumable NFTs
    • 📝NFT Mandates
    • 🎆Post-Mint Utility
    • 💼Partial Payment at Mint
  • For Developers
    • NFT Rental
    • API Reference
      • ⚙️Utility Integration
        • 👥Client
          • Register
          • Verify
          • Redeem Code
          • Get All Claimed Utility User
        • 👨‍💻Developer
          • Get All Benefits By Collection
      • 👾Rental Integration
        • User NFTs
        • Raw Transactions (Advanced)
      • 💰Loan Integration
        • User Loans
        • Raw Transactions (Advanced)
      • 🛒Marketplace
    • SDK Reference
      • Utility Integration
      • Rental Integration
        • EVM
        • Solana
      • Loan Integration
        • EVM
        • Solana
      • Marketplace
    • On-Chain Reference
    • Wallet Provider Reference
      • 🔏Rental
        • EVM
        • Solana
      • 🔐Loan
        • EVM
        • Solana
    • ⛓️Supported Chains
  • For Users
    • 📚Step By Step Rent Tutorial
    • 📚Step By Step Loan tutorial
    • 📚Step by Step Utility Tutorial
      • Step by Step Utility Creation Tutorial
      • Step by step utility discover tutorial
    • 💡Hedera Token Association
    • 🔏Privacy Policy
    • 🔑Terms of Service
  • Community
    • 🌐Website
    • 👽Discord
    • 🐦Twitter
Powered by GitBook
On this page

Was this helpful?

  1. For Developers
  2. SDK Reference

Utility Integration

PreviousSDK ReferenceNextRental Integration

Last updated 6 months ago

Was this helpful?

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-test');

//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-test');

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-test');

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-test');

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-test');

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-test');

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-test');

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-test');

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-test');

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