SDK Reference
init
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);
Greeter
import {
Greeter,
} from "@zerochain/zus-sdk";
const greetMessage = Greeter("john doe");
getBalance
import {
getBalance,
} from "@zerochain/zus-sdk";
const wallet = await getBalance(clientID);
sendTransaction
import {
sendTransaction,
} from "@zerochain/zus-sdk";
const fromWallet = {
id: clientID,
public_key: publicKey,
secretKey: privateKey,
};
await sendTransaction(fromWallet, sendTo, parseInt(sendAmount), "");
getBalanceWasm
import {
getBalanceWasm,
} from "@zerochain/zus-sdk";
const wallet = await getBalanceWasm(clientID);
setWallet
import {
setWallet,
} from "@zerochain/zus-sdk";
await setWallet(clientID, privateKey, publicKey, mnemonic);
listAllocations
import {
listAllocations,
} from "@zerochain/zus-sdk";
const allocations = await listAllocations();
createAllocation
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
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
import {
getAllocation,
} from "@zerochain/zus-sdk";
const allocation = await getAllocation(selectedAllocation);
getAllocationFromAuthTicket
import {
getAllocationFromAuthTicket,
} from "@zerochain/zus-sdk";
const allocation = await getAllocationFromAuthTicket(authTicket);
reloadAllocation
import {
reloadAllocation,
} from "@zerochain/zus-sdk";
const allocation = await reloadAllocation(selectedAllocation);
freezeAllocation
import {
freezeAllocation,
} from "@zerochain/zus-sdk";
await freezeAllocation(selectedAllocation);
cancelAllocation
import {
cancelAllocation,
} from "@zerochain/zus-sdk";
await cancelAllocation(selectedAllocation);
updateAllocation
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
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
import {
download,
} from "@zerochain/zus-sdk";
const file = await download(
allocationId,
path,
"",
"",
false,
10,
"downloadCallback"
);
getFaucetToken
import {
getFaucetToken,
} from "@zerochain/zus-sdk";
await getFaucetToken();
executeSmartContract
import {
executeSmartContract,
} from "@zerochain/zus-sdk";
await executeSmartContract(address, methodName, input, value);
listObjects
import {
listObjects,
} from "@zerochain/zus-sdk";
const list = await listObjects(selectedAllocation, "/");
share
import {
share,
} from "@zerochain/zus-sdk";
const authTicket = await share(allocationId, path, "", "", 0, false, 0);
showLogs
import {
showLogs,
} from "@zerochain/zus-sdk";
await showLogs();
hideLogs
import {
hideLogs,
} from "@zerochain/zus-sdk";
await hideLogs();
deleteObject
import {
deleteObject,
} from "@zerochain/zus-sdk";
await deleteObject(selectedAllocation, path);
renameObject
import {
renameObject,
} from "@zerochain/zus-sdk";
await renameObject(
selectedAllocation,
path,
newPath
);
copyObject
import {
copyObject,
} from "@zerochain/zus-sdk";
await copyObject(selectedAllocation, path, destPath);
moveObject
import {
moveObject,
} from "@zerochain/zus-sdk";
await moveObject(selectedAllocation, path, destPath);
play
import { play } from "@zerochain/zus-sdk";
await play(allocationId, remotePath, authTicket, lookupHash, isLive);
stop
import { stop } from "@zerochain/zus-sdk";
stop();
getNextSegment
import { getNextSegment } from "@zerochain/zus-sdk";
const buf = await getNextSegment();
createDir
import {
createDir,
} from "@zerochain/zus-sdk";
await createDir(selectedAllocation, "/" + dirName);
getFileStats
import {
getFileStats,
} from "@zerochain/zus-sdk";
const fileStats = await getFileStats(selectedAllocation, path);
downloadBlocks
import {
downloadBlocks,
} from "@zerochain/zus-sdk";
const output = await downloadBlocks(
selectedAllocation,
path,
"",
"",
10,
0,
10
);
getUSDRate
import {
getUSDRate,
} from "@zerochain/zus-sdk";
const rate = await getUSDRate("zcn");
isWalletID
import {
isWalletID,
} from "@zerochain/zus-sdk";
const output = await isWalletID(clientId);
getPublicEncryptionKey
import {
getPublicEncryptionKey,
} from "@zerochain/zus-sdk";
const key = await getPublicEncryptionKey(mnemonic);
getLookupHash
import {
getLookupHash,
} from "@zerochain/zus-sdk";
const hash = await getLookupHash(selectedAllocation, path);
getAllocationBlobbers
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
import {
getBlobberIds,
} from "@zerochain/zus-sdk";
const blobberUrls = [
"https://dev2.zus.network/blobber02",
"https://dev1.zus.network/blobber02",
];
const blobberIds = await getBlobberIds(blobberUrls);
getBlobbers
import {
getBlobbers,
} from "@zerochain/zus-sdk";
result = await getBlobbers();
createReadPool
import {
createReadPool,
} from "@zerochain/zus-sdk";
const result = await createReadPool();
getReadPoolInfo
import {
getReadPoolInfo,
} from "@zerochain/zus-sdk";
const result = await getReadPoolInfo(clientId);
lockWritePool
import {
lockWritePool,
} from "@zerochain/zus-sdk";
const result = await lockWritePool(allocationId, 1000, 10);
createWallet
import {
createWallet,
} from "@zerochain/zus-sdk";
const wallet = await createWallet();
recoverWallet
import {
recoverWallet,
} from "@zerochain/zus-sdk";
const wallet = await recoverWallet(mnemonic);
decodeAuthTicket
import {
decodeAuthTicket,
} from "@zerochain/zus-sdk";
const result = await decodeAuthTicket(authTicket);
initBridge
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
import {
burnZCN,
} from "@zerochain/zus-sdk";
const hash = await burnZCN(amount);
mintZCN
import {
mintZCN,
} from "@zerochain/zus-sdk";
const hash = await mintZCN(burnTrxHash, timeout);
getMintWZCNPayload
import {
getMintWZCNPayload,
} from "@zerochain/zus-sdk";
const result = await getMintWZCNPayload(burnTrxHash);
Last modified 2h ago