SDK Reference
Function | Description |
---|---|
Initialize the SDK |
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 |
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 |
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 |
Function | Description |
---|---|
Get Blobbers with filters for creating the allocation | |
Convert blobber urls to blobber ids | |
Get blobbers from the network |
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 |
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);
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);
Get wallet balance
import {
getBalance,
} from "@zerochain/zus-sdk";
const wallet = await getBalance(clientID);
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), "");
Get wallet balance using wasm
import {
getBalanceWasm,
} from "@zerochain/zus-sdk";
const wallet = await getBalanceWasm(clientID);
List all the allocations
import {
listAllocations,
} from "@zerochain/zus-sdk";
const allocations = await listAllocations();
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);
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);
Get allocation details
import {
getAllocation,
} from "@zerochain/zus-sdk";
const allocation = await getAllocation(selectedAllocation);
Get allocation details based on authTicket
import {
getAllocationFromAuthTicket,
} from "@zerochain/zus-sdk";
const allocation = await getAllocationFromAuthTicket(authTicket);
Clear the cache and get the allocation details from blockchain
import {
reloadAllocation,
} from "@zerochain/zus-sdk";
const allocation = await reloadAllocation(selectedAllocation);
Freeze the allocation so that the allocation data can no longer be modified
import {
freezeAllocation,
} from "@zerochain/zus-sdk";
await freezeAllocation(selectedAllocation);
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);
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
);
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 your own file or a shared file.
import {
download,
} from "@zerochain/zus-sdk";
const file = await download(
allocationId,
path,
"",
"",
false,
10,
"downloadCallback"
);
Get the test tokens for testing
import {
getFaucetToken,
} from "@zerochain/zus-sdk";
await getFaucetToken();
Send the raw SmartContract transaction, and verify the result
import {
executeSmartContract,
} from "@zerochain/zus-sdk";
await executeSmartContract(address, methodName, input, value);
List the files with the allocationID and remotePath
import {
listObjects,
} from "@zerochain/zus-sdk";
const list = await listObjects(selectedAllocation, "/");
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);
Enable the toggle to show the logs
import {
showLogs,
} from "@zerochain/zus-sdk";
await showLogs();
Enable the toggle to hide the logs
import {
hideLogs,
} from "@zerochain/zus-sdk";
await hideLogs();
Delete the remote file from blobbers
import {
deleteObject,
} from "@zerochain/zus-sdk";
await deleteObject(selectedAllocation, path);
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
);
Copy the file to another folder path on blobbers
import {
copyObject,
} from "@zerochain/zus-sdk";
await copyObject(selectedAllocation, path, destPath);
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 and stream the video files
import { play } from "@zerochain/zus-sdk";
await play(allocationId, remotePath, authTicket, lookupHash, isLive);
Stops the current play
import { stop } from "@zerochain/zus-sdk";
stop();
Gets the next segment
import { getNextSegment } from "@zerochain/zus-sdk";
const buf = await getNextSegment();
Create a folder on the blobbers
import {
createDir,
} from "@zerochain/zus-sdk";
await createDir(selectedAllocation, "/" + dirName);
Gets the file stats
import {
getFileStats,
} from "@zerochain/zus-sdk";
const fileStats = await getFileStats(selectedAllocation, path);
Download the blocks of a file
import {
downloadBlocks,
} from "@zerochain/zus-sdk";
const output = await downloadBlocks(
selectedAllocation,
path,
"",
"",
10,
0,
10
);
Get the USD rate by token symbol (eg zcn, eth)
import {
getUSDRate,
} from "@zerochain/zus-sdk";
const rate = await getUSDRate("zcn");
Check whether the wallet id is valid
import {
isWalletID,
} from "@zerochain/zus-sdk";
const output = await isWalletID(clientId);
Get the public encryption key by mnemonic
import {
getPublicEncryptionKey,
} from "@zerochain/zus-sdk";
const key = await getPublicEncryptionKey(mnemonic);
Get the lookup hash by allocation id and path
import {
getLookupHash,
} from "@zerochain/zus-sdk";
const hash = await getLookupHash(selectedAllocation, path);
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
);
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);
Get blobbers from the network
import {
getBlobbers,
} from "@zerochain/zus-sdk";
result = await getBlobbers();
Create the readpool in storage SC if the pool is missing.
import {
createReadPool,
} from "@zerochain/zus-sdk";
const result = await createReadPool();
Gets the information about the read pool for the allocation
import {
getReadPoolInfo,
} from "@zerochain/zus-sdk";
const result = await getReadPoolInfo(clientId);
Locks given number of tokes for given duration in write pool
import {
lockWritePool,
} from "@zerochain/zus-sdk";
const result = await lockWritePool(allocationId, 1000, 10);
Create the wallet
import {
createWallet,
} from "@zerochain/zus-sdk";
const wallet = await createWallet();
Recover the wallet using mnemonic
import {
recoverWallet,
} from "@zerochain/zus-sdk";
const wallet = await recoverWallet(mnemonic);
Decodes an authTicket
import {
decodeAuthTicket,
} from "@zerochain/zus-sdk";
const result = await decodeAuthTicket(authTicket);
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
);
Bridge method to burn the ZCN
import {
burnZCN,
} from "@zerochain/zus-sdk";
const hash = await burnZCN(amount);
Bridge method to mint the ZCN
import {
mintZCN,
} from "@zerochain/zus-sdk";
const hash = await mintZCN(burnTrxHash, timeout);
Bridge method to get Mint WZCN Payload
import {
getMintWZCNPayload,
} from "@zerochain/zus-sdk";
const result = await getMintWZCNPayload(burnTrxHash);
Last modified 2mo ago