- Notifications
You must be signed in to change notification settings - Fork0
The Nuklai SDK provides a modular and comprehensive interface for interacting with the Nuklai blockchain.
License
Nuklai/nuklai-js-sdk
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
A modular interface for interacting with the Nuklai blockchain, built on top of theAvalanche HyperSDK.
npm install @nuklai/nuklai-sdk# oryarn add @nuklai/nuklai-sdk
import{NuklaiSDK}from"@nuklai/nuklai-sdk";constsdk=newNuklaiSDK("http://127.0.0.1:9650");consthealthStatus=awaitsdk.rpcService.validateConnection();
- 💰 Asset Management (Fungible/Non-Fungible Tokens)
- 📊 Dataset Creation and Management
- 🏪 Marketplace Operations
- 💳 Transaction Management
- 🔍 Network Status and Health Checks
- 🏛️ Validator Management
- 📈 Staking Operations
import{NuklaiSDK}from"@nuklai/nuklai-sdk";constsdk=newNuklaiSDK({baseApiUrl:"http://127.0.0.1:9650",});// Set the signer for transactionssdk.rpcService.setSigner("your-private-key-here");
// Create SDK instanceconstsdk=newNuklaiSDK();// Create a new random walletconstwallet=sdk.createWallet();console.log("Wallet address:",wallet.getAddress());// Get wallet's private keyconstprivateKey=wallet.getPrivateKey();console.log("Private key:",privateKey);// Returns the 128-character private key string// Or import an existing walletconstimportedWallet=sdk.importWalletFromPrivateKey("your-private-key-hex");// Check wallet connectionif(sdk.isWalletConnected()){// Use wallet featuresconstaddress=sdk.getAddress();}
// Using a private key stringawaitsdk.rpcService.setSigner(privateKeyString);// Using any custom signer that implements SignerIfaceawaitsdk.rpcService.setSigner(customSigner);
// Create a fungible tokenconstftResult=awaitsdk.rpcService.createFTAsset("Test Token","TEST",9,"metadata",BigInt("1000000000000000000"),// Max supply"owner-address","admin-address","admin-address","admin-address");// Create an NFT collectionconstnftResult=awaitsdk.rpcService.createNFTAsset("Test NFT","TNFT","metadata",BigInt(1000),// Max supply"owner-address","admin-address","admin-address","admin-address");
// Mint fungible tokensconstmintAmount=BigInt("1000000000000000000");// 1 tokenconstmintResult=awaitsdk.rpcService.mintFTAsset("receiver-address","token-address",mintAmount);// Mint NFTconstnftMintResult=awaitsdk.rpcService.mintNFTAsset("nft-collection-address",JSON.stringify({name:"Test NFT #1",description:"First NFT",attributes:[],}),"receiver-address");// Transfer tokensconsttransferAmount=BigInt("100000000000000000");// 0.1 tokenconsttransferResult=awaitsdk.rpcService.transfer("recipient-address","token-address",transferAmount,"Transfer memo");
// Get native NAI token balanceconstnativeBalance=awaitsdk.rpcService.getBalance("address");// Get any asset balance by passing asset addressconstassetBalance=awaitsdk.rpcService.getBalance("address","assetAddress");
NOTE: Balance is returned as raw strings without decimal formatting. Use asset decimals info from
getAssetInfo()
to correctly format & display the balance corectly.
// Create a datasetconstresult=awaitsdk.rpcService.createDataset("asset-address","Test Dataset","Description","AI,Testing","MIT","MIT","https://opensource.org/licenses/MIT","metadata",true// isCommunityDataset);
Build from source:
yarnyarn build
Run tests:
yarntest
Theexamples/
directory contains sample implementations:
examples/├── datasets.ts # Dataset creation and management├── fungible-tokens.ts # Fungible Token operations├── non-fungible-tokens.ts # Non-Fungible Token operations└── marketplace.ts # Marketplace interactions
You can run all examples at once using:
yarn examples
Or run individual examples:
ts-node --esm examples/fungible-tokens.tsts-node --esm examples/non-fungible-tokens.ts
All methods are accessible through thesdk.rpcService
instance. Below is a comprehensive reference of available methods grouped by their functionality.
Method | Description | Parameters | Returns |
---|---|---|---|
validateConnection() | Checks node connectivity | None | Promise<boolean> |
getEmissionInfo() | Retrieves emission statistics | None | Promise<ActionOutput> |
getAllValidators() | Lists all validators | None | Promise<ActionOutput> |
getStakedValidators() | Lists validators with stake | None | Promise<ActionOutput> |
getValidatorStake(nodeID) | Gets specific validator stake | nodeID: string | Promise<ActionOutput> |
Method | Description | Parameters | Returns |
---|---|---|---|
createFTAsset() | Creates a new Fungible Token | -name: string - symbol: string - decimals: number - metadata: string - maxSupply: bigint - mintAdmin: string - pauseAdmin: string - freezeAdmin: string - kycAdmin: string | Promise<TxResult> |
mintFTAsset() | Mints Fungible Tokens | -to: string - assetAddress: string - amount: bigint | Promise<TxResult> |
transfer() | Transfers tokens | -to: string - assetAddress: string - value: bigint - memo: string | Promise<TxResult> |
Method | Description | Parameters | Returns |
---|---|---|---|
createNFTAsset() | Creates an NFT collection | -name: string - symbol: string - metadata: string - maxSupply: bigint - mintAdmin: string - pauseAdmin: string - freezeAdmin: string - kycAdmin: string | Promise<TxResult> |
mintNFTAsset() | Mints a new NFT | -assetAddress: string - metadata: string - to: string | Promise<TxResult> |
Method | Description | Parameters | Returns |
---|---|---|---|
createDataset() | Creates a new dataset | -assetAddress: string - name: string - description: string - categories: string - licenseName: string - licenseSymbol: string - licenseURL: string - metadata: string - isCommunityDataset: boolean | Promise<TxResult> |
updateDataset() | Updates dataset info | -datasetAddress: string - name: string - description: string - categories: string - licenseName: string - licenseSymbol: string - licenseURL: string - isCommunityDataset: boolean | Promise<TxResult> |
getDatasetInfo() | Gets dataset details | datasetID: string | Promise<ActionOutput> |
Method | Description | Parameters | Returns |
---|---|---|---|
publishDatasetToMarketplace() | Lists dataset on marketplace | -datasetAddress: string - paymentAssetAddress: string - datasetPricePerBlock: number | Promise<TxResult> |
subscribeDatasetMarketplace() | Subscribes to dataset | -marketplaceAssetAddress: string - paymentAssetAddress: string - numBlocksToSubscribe: number | Promise<TxResult> |
claimMarketplacePayment() | Claims marketplace earnings | -marketplaceAssetAddress: string - paymentAssetAddress: string | Promise<TxResult> |
Method | Description | Parameters | Returns |
---|---|---|---|
getBalance() | Get's address balance | address: string | Promise<string> |
getAssetInfo() | Get's asset details | assetAddress: string | Promise<ActionOutput> |
getDatasetBalance() | Get's dataset balance | -address: string - assetID: string | Promise<ActionOutput> |
getDatasetNFTInfo() | Get's NFT details | nftID: string | Promise<ActionOutput> |
getPendingContributions() | Lists pending contributions | datasetID: string | Promise<ActionOutput> |
getPrivateKey() | Get's wallet's private key | None | string |
getAddress() | Get's wallet's address | None | string |
getPublicKey() | Get's wallet's public key | None | string |
Creating and minting a fungible token
// Create a FTconstftResult=awaitsdk.rpcService.createFTAsset("Test Token","TEST",9,"metadata",BigInt("1000000000000000000"),"owner-address","admin-address","admin-address","admin-address");// After creation, mint some tokensconstmintResult=awaitsdk.rpcService.mintFTAsset("receiver-address",ftResult.result[0].asset_address,BigInt("1000000000000000000"));
MIT License - seeLICENSE for details.
About
The Nuklai SDK provides a modular and comprehensive interface for interacting with the Nuklai blockchain.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors2
Uh oh!
There was an error while loading.Please reload this page.