☁️
Züs
  • About Züs
  • Concepts
    • Architecture
      • Mining on the Züs Blockchain
        • Onboarding a New Miner or Sharder
        • Block Production Protocol
        • Block Finalization
        • Merkle Patricia Trees(MPT) and Recovery
        • View Change and Distributed Key Generation(DKG)
      • Payment
      • Storage
      • Token Bridge Protocol
      • Resources
    • Tokenomics
      • Staking Process
      • Block Rewards
      • Delegation
    • Store
    • Earn
    • Build
    • NFT
  • Resources
    • Whitepapers
      • Tokenomics Paper
      • Architecture Paper
      • Storage Paper
    • Patents
      • NON-FUNGIBLE TOKEN BLOCKCHAIN PROCESSING
      • FREE STORAGE PROTOCOL FOR BLOCKCHAIN PLATFORM
      • TRANSFERRING CONTENT VIA PROXY RE-ENCRYPTION
      • STREAMING CONTENT VIA BLOCKCHAIN TECHNOLOGY
      • SPLIT-KEY WALLET ACCESS BETWEEN BLOCKCHAINS
      • ENFORCING SECURITY PARAMETERS SPECIFIED BY AN OWNER ON A BLOCKCHAIN PLATFORM
      • CLIENT AUTHENTICATION USING SPLIT KEY SIGNING ON A BLOCKCHAIN PLATFORM
      • BLOCKCHAIN CONTENT PURCHASING PROTOCOL
      • BLOCKCHAIN BASED PRIVACY COMPLIANCE PLATFORM
      • SYSTEMS AND METHODS OF SELF-ADMINISTERED PROTOCOLS ON A BLOCKCHAIN PLATFORM
      • SYSTEMS AND METHODS OF AGGREGATE SIGNING OF DIGITAL SIGNATURES ON MULTIPLE MESSAGES SIMULTANEOUSLY U
      • SYSTEMS AND METHODS OF BLOCKCHAIN PLATFORM FOR AUTOMATED ASSET BASED PROVISIONING OF RESOURCES
      • SYSTEMS AND METHODS OF SELF-FORKING BLOCKCHAIN PROTOCOL
      • SYSTEMS AND METHODS OF SUSTAINABILITY PROTOCOL USING DISTRIBUTED BLOCKCHAIN APPLICATION WITH IoT SEN
      • SYSTEMS AND METHODS OF BLOCKCHAIN PLATFORM FOR DISTRIBUTED APPLICATIONS
  • API Reference
    • Endpoints
      • Block
      • Client
      • Connection
      • DNS
      • File
      • Smart Contracts
      • Blobber Stats
      • Transactions
      • Miners and Sharders
        • Stats
        • State
        • Diagnostics
        • Configuration
        • Smart Contract State
        • Smart Contract Stats
        • Chain Stats
  • Hackathon
    • Register to Hackathon
      • How to Add Members to Hackathon Team
    • Repos
    • Documentation
  • Products
    • Bolt
      • Get Started
      • Stake
      • Activity
      • Buy ZCN
      • Sell ZCN
      • Send Tokens
      • Receive Tokens
      • Settings
        • Manage Profile
        • Wallet
        • Read Pool
      • Troubleshooting
    • Vult
      • Sign Up
      • Upload File
      • Upload an Encrypted File
      • Upload a File to a Folder
      • Share a Uploaded File
      • Move a Uploaded File
      • Delete a File
      • Make File Available Offline
      • Troubleshooting
    • Atlus
      • Dashboard Overview
      • Service Providers
      • Charts
        • Market Charts
        • Network Charts
        • Storage Charts
        • Züs Explainer
      • Blockchain
      • Server Map
    • Blimp
      • Sign Up
        • Buy ZCN for Storage
      • Use Blimp as Direct Storage
      • Use Blimp as S3 Server
        • S3 Operations
      • Use Blimp for Cloud Migration
      • Manage Allocations
        • Extend Size
        • Extend Duration
        • Add Blobber
        • Replace Blobber
        • Make allocation Immutable
        • Freeze Allocation
        • Cancel Allocation
    • Chimney
      • Get Started
      • Deploy Blobber on Own Server
      • Deploy Blobber on Rented Server
      • Stake Blobber
      • Add Blobber
      • Monitor Blobbers
      • Visualize Blobber Logs
      • View Blobber Rank
    • Chalk
      • Sign Up
      • Create NFT Collection
        • Buy ZCN for NFT via ERC token
        • Buy ZCN for NFT via Credit card
      • Explore NFT Collections
      • My NFTs
      • Profile
        • Withdraw Earnings
        • Manage Collections
  • Guides
    • Zus GO SDK
    • Zus JS SDK
    • Zbox CLI
      • Repo
      • Get Started
      • Creating and Managing Allocations
      • Uploading and Managing Files
      • Lock and Unlock Tokens
      • Tips and Troubleshooting
    • Zwallet CLI
      • Repo
      • Get Started
      • Zwallet Operations
      • Staking on miners and sharders
      • Burn and Mint Tokens using Zwallet
      • Troubleshooting
    • Add a Blobber
      • Repo
      • Getting Started
    • Add a Miner/Sharder
      • Repo
      • Getting Started
    • Setup a Blockchain
      • Repo
      • Quickstart
        • Understand the Script
      • Step 1: Set up the project
      • Step 2: Setup the network for Züs components
      • Step 3: Initialize and Build the Züs components
      • Step 4: Start Sharder and Miner Containers
      • Step 5 : Create a wallet using zwalletcli
      • Step 6: Starting the blobber containers
      • Step 7: Validate Züs deployment
      • Step 8: Creating an Allocation on Blobber
      • Restarting Sharder and Miner Containers with CleanDB.
      • Additional Tips and Troubleshooting
    • Glossary
  • Support
    • Help Center
      • Community
      • Issues on Github
      • Contact Us
Powered by GitBook
On this page
  • Initialize SDK
  • Wallet Functions
  • Storage Functions
  • FIle Operation Functions
  • Blobber Functions
  • Smart Contract Functions
  • init
  • setWallet
  • getBalance
  • sendTransaction
  • getBalanceWasm
  • listAllocations
  • createAllocation
  • createAllocationWithBlobbers
  • getAllocation
  • getAllocationFromAuthTicket
  • reloadAllocation
  • freezeAllocation
  • cancelAllocation
  • updateAllocation
  • bulkUpload
  • download
  • getFaucetToken
  • executeSmartContract
  • listObjects
  • share
  • showLogs
  • hideLogs
  • deleteObject
  • renameObject
  • copyObject
  • moveObject
  • play
  • stop
  • getNextSegment
  • createDir
  • getFileStats
  • downloadBlocks
  • getUSDRate
  • isWalletID
  • getPublicEncryptionKey
  • getLookupHash
  • getAllocationBlobbers
  • getBlobberIds
  • getBlobbers
  • createReadPool
  • getReadPoolInfo
  • lockWritePool
  • createWallet
  • recoverWallet
  • decodeAuthTicket
  • initBridge
  • burnZCN
  • mintZCN
  • getMintWZCNPayload
  1. Guides
  2. Züs js-sdk

SDK Reference

Initialize SDK

Function
Description

Initialize the SDK

Wallet Functions

Function
Description

Set the Wallet Details

Get Wallet Balance

Send token from one wallet to another

Get Wallet balance using wasm

Get the USD rate by token symbol (e g zcn,eth)

Check whether the wallet id is valid

Get the public encryption key by wallet mnemonic

Get test tokens for testing

Create the wallet

Recover the wallet using wallet mnemonic phrase

Initalize the bridge for calling burn and mint functions

Bridge method to burn ZCN tokens

Bridge method to mint ZCN tokens

Bridge method to get Mint WZCN Payload

Storage Functions

Function
Description

List all the allocations

Create an Allocation

Create an allocation with the given preferred blobbers

Get Allocation Details

Get allocation details based on authTicket

Clear the cache and get the allocation details from blockchain

Freeze the allocation so that the allocation data can no longer be modified

Cancel Allocation

Update the allocation settings

FIle Operation Functions

Function
Description

Bulk Upload FIles with json options

Download your own file or a shared file

List the files with allocationID and remotePath

Generate an authToken that provides the authorization to the holder to the specified file on the remotepath.

Decodes and authTicket

Delete the remote file from blobbers

Rename a file existing already on dStorage. Only the allocation's owner can rename a file

Copy the file to another folder path on blobbers

Move the file to another remote folder path on dStorage. Only the owner of the allocation can copy an object.

Play and stream the video files

Stops the current play

Gets the next segment

Create a folder on the blobbers

Gets the file stats

Download the blocks of a file

Get the lookup hash by allocation id and file path

Blobber Functions

Function
Description

Get Blobbers with filters for creating the allocation

Convert blobber urls to blobber ids

Get blobbers from the network

Smart Contract Functions

Function
Description

Send the raw SmartContract transaction, and verify the result.

Create the readpool in storage SC if the pool is missing.

Gets the information about the read pool for the allocation

Locks given number of tokes for given duration in write pool

Enable the toggle to show the logs

Enable the toggle to hide the logs

init

Initialize the SDK.

Note: Call setWallet method after initializing the SDK. This is mandatory before calling other methods in the SDK.

import {
  init
} from "@zerochain/zus-sdk";

const configJson = {
  chainId: "0afc093ffb509f059c55478bc1a60351cef7b4e9c008a53a6cc8241ca8617dfe",
  signatureScheme: "bls0chain",
  minConfirmation: 50,
  minSubmit: 50,
  confirmationChainLength: 3,
  blockWorker: "https://dev.zus.network/dns",
  zboxHost: "https://0box.dev.zus.network",
  zboxAppType: "vult",
};

const config = [
  configJson.chainId,
  configJson.blockWorker,
  configJson.signatureScheme,
  configJson.minConfirmation,
  configJson.minSubmit,
  configJson.confirmationChainLength,
  configJson.zboxHost,
  configJson.zboxAppType,
];

await init(config);

setWallet

Set the wallet details

Note: Call setWallet method after initializing the SDK. This is mandatory before calling other methods in the SDK.

import {
  setWallet,
} from "@zerochain/zus-sdk";

await setWallet(clientID, privateKey, publicKey, mnemonic);

getBalance

Get wallet balance

import {
  getBalance,
} from "@zerochain/zus-sdk";

const wallet = await getBalance(clientID);

sendTransaction

Send the token from one wallet to another

import {
  sendTransaction,
} from "@zerochain/zus-sdk";

const fromWallet = {
      id: clientID,
      public_key: publicKey,
      secretKey: privateKey,
};

await sendTransaction(fromWallet, sendTo, parseInt(sendAmount), "");

getBalanceWasm

Get wallet balance using wasm

import {
  getBalanceWasm,
} from "@zerochain/zus-sdk";

const wallet = await getBalanceWasm(clientID);

listAllocations

List all the allocations

import {
  listAllocations,
} from "@zerochain/zus-sdk";

const allocations = await listAllocations();

createAllocation

Create an allocation

import {
  createAllocation,
} from "@zerochain/zus-sdk";

const config = {
    name: "newalloc",
    datashards: 2,
    parityshards: 2,
    size: 2 * 1073741824,
    expiry: Math.floor(expiry.getTime() / 1000),
    minReadPrice: 0,
    maxReadPrice: 184467440737095516,
    minWritePrice: 0,
    maxWritePrice: 184467440737095516,
    lock: 5000000000,
};

await createAllocation(config);

createAllocationWithBlobbers

Create an allocation with the given preferred blobbers

import {
  createAllocationWithBlobbers,
} from "@zerochain/zus-sdk";

const config = {
    datashards: 2,
    parityshards: 2,
    size: 2 * 1073741824,
    expiry: Math.floor(expiry.getTime() / 1000),
    minReadPrice: 0,
    maxReadPrice: 184467440737095516,
    minWritePrice: 0,
    maxWritePrice: 184467440737095516,
    lock: 5000000000,
    blobbers: preferredBlobbers,
};

await createAllocationWithBlobbers(config);

getAllocation

Get allocation details

import {
  getAllocation,
} from "@zerochain/zus-sdk";

const allocation = await getAllocation(selectedAllocation);

getAllocationFromAuthTicket

Get allocation details based on authTicket

import {
  getAllocationFromAuthTicket,
} from "@zerochain/zus-sdk";

const allocation = await getAllocationFromAuthTicket(authTicket);

reloadAllocation

Clear the cache and get the allocation details from blockchain

import {
  reloadAllocation,
} from "@zerochain/zus-sdk";

const allocation = await reloadAllocation(selectedAllocation);

freezeAllocation

Freeze the allocation so that the allocation data can no longer be modified

import {
  freezeAllocation,
} from "@zerochain/zus-sdk";

await freezeAllocation(selectedAllocation);

cancelAllocation

Immediately return all the remaining tokens from challenge pool back to the allocation's owner and cancels the allocation. If blobbers already got some tokens, the tokens will not be returned. Remaining min lock payment to the blobber will be funded from the allocation's write pools.

import {
  cancelAllocation,
} from "@zerochain/zus-sdk";

await cancelAllocation(selectedAllocation);

updateAllocation

Update the allocation settings

import {
  updateAllocation,
} from "@zerochain/zus-sdk";

const size = undefined,
    expiry = 2628000,
    lock = 100,
    updateTerms = true,
    addBlobberId = "",
    removeBlobberId = "";

//Call updateAllocation method
await updateAllocation(
  selectedAllocation,
  size,
  expiry,
  lock,
  updateTerms,
  addBlobberId,
  removeBlobberId
);

bulkUpload

Bulk upload files with json options

import {
  bulkUpload,
} from "@zerochain/zus-sdk";

const objects = [];
for (const file of filesForUpload) {
  objects.push({
    allocationId: allocationId,
    remotePath: `/${file.name}`,
    file: file,
    thumbnailBytes: "",
    encrypt: false,
    isUpdate: false,
    isRepair: false,
    numBlocks: 100,
    callback: function (totalBytes, completedBytes, error) {
      console.log(
        file.name +
          " " +
          completedBytes +
          "/" +
          totalBytes +
          " err:" +
          error
      );
    },
  });
}

const results = await bulkUpload(objects);

download

Download your own file or a shared file.

import {
  download,
} from "@zerochain/zus-sdk";

const file = await download(
        allocationId,
        path,
        "",
        "",
        false,
        10,
        "downloadCallback"
      );

getFaucetToken

Get the test tokens for testing

import {
  getFaucetToken,
} from "@zerochain/zus-sdk";

await getFaucetToken();

executeSmartContract

Send the raw SmartContract transaction, and verify the result

import {
  executeSmartContract,
} from "@zerochain/zus-sdk";

await executeSmartContract(address, methodName, input, value);

listObjects

List the files with the allocationID and remotePath

import {
  listObjects,
} from "@zerochain/zus-sdk";

const list = await listObjects(selectedAllocation, "/");

share

Generate an authToken that provides the authorization to the holder to the specified file on the remotepath.

import {
  share,
} from "@zerochain/zus-sdk";

const authTicket = await share(allocationId, path, "", "", 0, false, 0);

showLogs

Enable the toggle to show the logs

import {
  showLogs,
} from "@zerochain/zus-sdk";

await showLogs();

hideLogs

Enable the toggle to hide the logs

import {
  hideLogs,
} from "@zerochain/zus-sdk";

await hideLogs();

deleteObject

Delete the remote file from blobbers

import {
  deleteObject,
} from "@zerochain/zus-sdk";

await deleteObject(selectedAllocation, path);

renameObject

Rename a file existing already on dStorage. Only the allocation's owner can rename a file.

import {
  renameObject,
} from "@zerochain/zus-sdk";

await renameObject(
      selectedAllocation,
      path,
      newPath
    );

copyObject

Copy the file to another folder path on blobbers

import {
  copyObject,
} from "@zerochain/zus-sdk";

await copyObject(selectedAllocation, path, destPath);

moveObject

Move the file to another remote folder path on dStorage. Only the owner of the allocation can copy an object.

import {
  moveObject,
} from "@zerochain/zus-sdk";

await moveObject(selectedAllocation, path, destPath);

play

Play and stream the video files

import { play } from "@zerochain/zus-sdk";

await play(allocationId, remotePath, authTicket, lookupHash, isLive);

stop

Stops the current play

import { stop } from "@zerochain/zus-sdk";

stop();

getNextSegment

Gets the next segment

import { getNextSegment } from "@zerochain/zus-sdk";

const buf = await getNextSegment();

createDir

Create a folder on the blobbers

import {
  createDir,
} from "@zerochain/zus-sdk";

await createDir(selectedAllocation, "/" + dirName);

getFileStats

Gets the file stats

import {
  getFileStats,
} from "@zerochain/zus-sdk";

const fileStats = await getFileStats(selectedAllocation, path);

downloadBlocks

Download the blocks of a file

import {
  downloadBlocks,
} from "@zerochain/zus-sdk";

const output = await downloadBlocks(
      selectedAllocation,
      path,
      "",
      "",
      10,
      0,
      10
    );

getUSDRate

Get the USD rate by token symbol (eg zcn, eth)

import {
  getUSDRate,
} from "@zerochain/zus-sdk";

const rate = await getUSDRate("zcn");

isWalletID

Check whether the wallet id is valid

import {
  isWalletID,
} from "@zerochain/zus-sdk";

const output = await isWalletID(clientId);

getPublicEncryptionKey

Get the public encryption key by mnemonic

import {
  getPublicEncryptionKey,
} from "@zerochain/zus-sdk";

const key = await getPublicEncryptionKey(mnemonic);

getLookupHash

Get the lookup hash by allocation id and path

import {
  getLookupHash,
} from "@zerochain/zus-sdk";

const hash = await getLookupHash(selectedAllocation, path);

getAllocationBlobbers

Get blobbers with filters for creating the allocation

import {
  getAllocationBlobbers,
} from "@zerochain/zus-sdk";

const referredBlobberURLs = [
      "https://dev2.zus.network/blobber02",
      "https://dev1.zus.network/blobber02",
    ],
    dataShards = 2,
    parityShards = 2,
    size = 2 * 1073741824,
    expiry = Math.floor(expiryDate.getTime() / 1000),
    minReadPrice = 0,
    maxReadPrice = 184467440737095516,
    minWritePrice = 0,
    maxWritePrice = 184467440737095516;

const blobberList = await getAllocationBlobbers(
    referredBlobberURLs,
    dataShards,
    parityShards,
    size,
    expiry,
    minReadPrice,
    maxReadPrice,
    minWritePrice,
    maxWritePrice
  );

getBlobberIds

convert blobber urls to blobber ids

import {
  getBlobberIds,
} from "@zerochain/zus-sdk";

const blobberUrls = [
      "https://dev2.zus.network/blobber02",
      "https://dev1.zus.network/blobber02",
    ];

const blobberIds = await getBlobberIds(blobberUrls);

getBlobbers

Get blobbers from the network

import {
  getBlobbers,
} from "@zerochain/zus-sdk";

result = await getBlobbers();

createReadPool

Create the readpool in storage SC if the pool is missing.

import {
  createReadPool,
} from "@zerochain/zus-sdk";

const result = await createReadPool();

getReadPoolInfo

Gets the information about the read pool for the allocation

import {
  getReadPoolInfo,
} from "@zerochain/zus-sdk";

const result = await getReadPoolInfo(clientId);

lockWritePool

Locks given number of tokes for given duration in write pool

import {
  lockWritePool,
} from "@zerochain/zus-sdk";

const result = await lockWritePool(allocationId, 1000, 10);

createWallet

Create the wallet

import {
  createWallet,
} from "@zerochain/zus-sdk";

const wallet = await createWallet();

recoverWallet

Recover the wallet using mnemonic

import {
  recoverWallet,
} from "@zerochain/zus-sdk";

const wallet = await recoverWallet(mnemonic);

decodeAuthTicket

Decodes an authTicket

import {
  decodeAuthTicket,
} from "@zerochain/zus-sdk";

const result = await decodeAuthTicket(authTicket);

initBridge

Initialize the bridge for calling other bridge methods

import {
  initBridge,
} from "@zerochain/zus-sdk";

const ethereumAddress = "0x5B9eb7E72247c45F6c4B8424FB2002151c57c54d",
      bridgeAddress = "0x2405e40161ea6da91AE0e95061e7A8462b4D5eEa",
      authorizersAddress = "0xB132C20A02AD7C38d88805F0e3fFDdfb54224C58",
      wzcnAddress = "0x10140fbca3a468A1c35F132D75659eF0EB5d95DB",
      ethereumNodeURL =
        "https://goerli.infura.io/v3/6141be73a15d47748af0dc14f53d57d7",
      gasLimit = 300000,
      value = 0,
      consensusThreshold = 75.0;

 await initBridge(
      ethereumAddress,
      bridgeAddress,
      authorizersAddress,
      wzcnAddress,
      ethereumNodeURL,
      gasLimit,
      value,
      consensusThreshold
    );

burnZCN

Bridge method to burn the ZCN

import {
  burnZCN,
} from "@zerochain/zus-sdk";

const hash = await burnZCN(amount);

mintZCN

Bridge method to mint the ZCN

import {
  mintZCN,
} from "@zerochain/zus-sdk";

const hash = await mintZCN(burnTrxHash, timeout);

getMintWZCNPayload

Bridge method to get Mint WZCN Payload

import {
  getMintWZCNPayload,
} from "@zerochain/zus-sdk";

const result = await getMintWZCNPayload(burnTrxHash);

Last updated 2 years ago

init
setWallet
getBalance
sendTransaction
getBalanceWasm
getUSDRate
isWalletID
getPublicEncryptionKey
getFaucetToken
createWallet
recoverWallet
initBridge
burnZCN
mintZCN
getMintWZCNPayload
listAllocations
createAllocation
createAllocationWithBlobbers
getAllocation
getAllocationFromAuthTicket
reloadAllocation
freezeAllocation
cancelAllocation
updateAllocation
bulkUpload
download
listObjects
share
decodeAuthTicket
deleteObject
renameObject
copyObject
moveObject
play
stop
getNextSegment
createDir
getFileStats
downloadBlocks
getLookupHash
getAllocationBlobbers
getBlobberIds
getBlobbers
executeSmartContract
createReadPool
getReadPoolInfo
lockWritePool
showLogs
hideLogs