Initialize SDK
Wallet Functions
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
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
Create an allocation with the given preferred blobbers
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
Update the allocation settings
FIle Operation Functions
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.
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
Create a folder on the blobbers
Download the blocks of a file
Get the lookup hash by allocation id and file path
Blobber Functions
Get Blobbers with filters for creating the allocation
Convert blobber urls to blobber ids
Get blobbers from the network
Smart Contract Functions
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.
Copy 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.
Copy import {
setWallet,
} from "@zerochain/zus-sdk";
await setWallet(clientID, privateKey, publicKey, mnemonic);
getBalance
Get wallet balance
Copy import {
getBalance,
} from "@zerochain/zus-sdk";
const wallet = await getBalance(clientID);
sendTransaction
Send the token from one wallet to another
Copy 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
Copy import {
getBalanceWasm,
} from "@zerochain/zus-sdk";
const wallet = await getBalanceWasm(clientID);
listAllocations
List all the allocations
Copy import {
listAllocations,
} from "@zerochain/zus-sdk";
const allocations = await listAllocations();
createAllocation
Create an allocation
Copy 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
Copy 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
Copy import {
getAllocation,
} from "@zerochain/zus-sdk";
const allocation = await getAllocation(selectedAllocation);
getAllocationFromAuthTicket
Get allocation details based on authTicket
Copy import {
getAllocationFromAuthTicket,
} from "@zerochain/zus-sdk";
const allocation = await getAllocationFromAuthTicket(authTicket);
reloadAllocation
Clear the cache and get the allocation details from blockchain
Copy 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
Copy 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.
Copy import {
cancelAllocation,
} from "@zerochain/zus-sdk";
await cancelAllocation(selectedAllocation);
updateAllocation
Update the allocation settings
Copy 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
Copy 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.
Copy import {
download,
} from "@zerochain/zus-sdk";
const file = await download(
allocationId,
path,
"",
"",
false,
10,
"downloadCallback"
);
getFaucetToken
Get the test tokens for testing
Copy import {
getFaucetToken,
} from "@zerochain/zus-sdk";
await getFaucetToken();
executeSmartContract
Send the raw SmartContract transaction, and verify the result
Copy import {
executeSmartContract,
} from "@zerochain/zus-sdk";
await executeSmartContract(address, methodName, input, value);
listObjects
List the files with the allocationID and remotePath
Copy 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.
Copy import {
share,
} from "@zerochain/zus-sdk";
const authTicket = await share(allocationId, path, "", "", 0, false, 0);
showLogs
Enable the toggle to show the logs
Copy import {
showLogs,
} from "@zerochain/zus-sdk";
await showLogs();
hideLogs
Enable the toggle to hide the logs
Copy import {
hideLogs,
} from "@zerochain/zus-sdk";
await hideLogs();
deleteObject
Delete the remote file from blobbers
Copy 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.
Copy import {
renameObject,
} from "@zerochain/zus-sdk";
await renameObject(
selectedAllocation,
path,
newPath
);
copyObject
Copy the file to another folder path on blobbers
Copy 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.
Copy import {
moveObject,
} from "@zerochain/zus-sdk";
await moveObject(selectedAllocation, path, destPath);
play
Play and stream the video files
Copy import { play } from "@zerochain/zus-sdk";
await play(allocationId, remotePath, authTicket, lookupHash, isLive);
stop
Stops the current play
Copy import { stop } from "@zerochain/zus-sdk";
stop();
getNextSegment
Gets the next segment
Copy import { getNextSegment } from "@zerochain/zus-sdk";
const buf = await getNextSegment();
createDir
Create a folder on the blobbers
Copy import {
createDir,
} from "@zerochain/zus-sdk";
await createDir(selectedAllocation, "/" + dirName);
getFileStats
Gets the file stats
Copy import {
getFileStats,
} from "@zerochain/zus-sdk";
const fileStats = await getFileStats(selectedAllocation, path);
downloadBlocks
Download the blocks of a file
Copy 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)
Copy import {
getUSDRate,
} from "@zerochain/zus-sdk";
const rate = await getUSDRate("zcn");
isWalletID
Check whether the wallet id is valid
Copy import {
isWalletID,
} from "@zerochain/zus-sdk";
const output = await isWalletID(clientId);
getPublicEncryptionKey
Get the public encryption key by mnemonic
Copy import {
getPublicEncryptionKey,
} from "@zerochain/zus-sdk";
const key = await getPublicEncryptionKey(mnemonic);
getLookupHash
Get the lookup hash by allocation id and path
Copy import {
getLookupHash,
} from "@zerochain/zus-sdk";
const hash = await getLookupHash(selectedAllocation, path);
getAllocationBlobbers
Get blobbers with filters for creating the allocation
Copy 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
Copy 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
Copy import {
getBlobbers,
} from "@zerochain/zus-sdk";
result = await getBlobbers();
createReadPool
Create the readpool in storage SC if the pool is missing.
Copy import {
createReadPool,
} from "@zerochain/zus-sdk";
const result = await createReadPool();
getReadPoolInfo
Gets the information about the read pool for the allocation
Copy import {
getReadPoolInfo,
} from "@zerochain/zus-sdk";
const result = await getReadPoolInfo(clientId);
lockWritePool
Locks given number of tokes for given duration in write pool
Copy import {
lockWritePool,
} from "@zerochain/zus-sdk";
const result = await lockWritePool(allocationId, 1000, 10);
createWallet
Create the wallet
Copy import {
createWallet,
} from "@zerochain/zus-sdk";
const wallet = await createWallet();
recoverWallet
Recover the wallet using mnemonic
Copy import {
recoverWallet,
} from "@zerochain/zus-sdk";
const wallet = await recoverWallet(mnemonic);
decodeAuthTicket
Decodes an authTicket
Copy import {
decodeAuthTicket,
} from "@zerochain/zus-sdk";
const result = await decodeAuthTicket(authTicket);
initBridge
Initialize the bridge for calling other bridge methods
Copy 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
Copy import {
burnZCN,
} from "@zerochain/zus-sdk";
const hash = await burnZCN(amount);
mintZCN
Bridge method to mint the ZCN
Copy import {
mintZCN,
} from "@zerochain/zus-sdk";
const hash = await mintZCN(burnTrxHash, timeout);
getMintWZCNPayload
Bridge method to get Mint WZCN Payload
Copy import {
getMintWZCNPayload,
} from "@zerochain/zus-sdk";
const result = await getMintWZCNPayload(burnTrxHash);