☁️
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
  1. Guides
  2. Züs js-sdk
  3. js-sdk sample webapp
  4. Describing Code

Adding Allocation Functionalities

Last updated 1 year ago

Allocation Functions
const initClick = async () => {
    //Initialize SDK
    await init(config);
};

const listAllocationsClick = async () => {
    //Call listAllocations method
    const allocations = await listAllocations();
    console.log("allocations", allocations);
    setAllocationList(allocations);
};

const createAllocationClick = async () => {
  const expiry = new Date();
  expiry.setDate(expiry.getDate() + 30);

//datashards, parityshards int, size, expiry int64,minReadPrice, maxReadPrice, minWritePrice, maxWritePrice int64, lock int64,preferredBlobberIds []string
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,
};

//Call createAllocation method
await createAllocation(config);
  listAllocationsClick();
  };

const createAllocationWithBlobbersClick = async () => {
  const preferredBlobbers = getBlobberListForAllocation();
  const expiry = new Date();
  expiry.setDate(expiry.getDate() + 30);

//datashards, parityshards int, size, expiry int64,minReadPrice, maxReadPrice, minWritePrice, maxWritePrice int64, lock int64,preferredBlobberIds []string
  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,
    };

    //Call createAllocation method
    await createAllocationWithBlobbers(config);
    listAllocationsClick();
  };

  const getAllocationDetailsClick = async (allocationId) => {
    //Call getAllocation method
    const allocation = await getAllocation(allocationId);
    console.log("allocation", allocation);
    setAllocationDetails(allocation);
  };

  const reloadAllocationClick = async (allocationId) => {
    //Call reloadAllocation method
    const allocation = await reloadAllocation(allocationId);
    console.log("allocation", allocation);
    setAllocationDetails(allocation);
  };

  const freezeAllocationClick = async (allocationId) => {
    //Call freezeAllocation method
    await freezeAllocation(allocationId);
  };

  const cancelAllocationClick = async (allocationId) => {
    //Call cancelAllocation method
    await cancelAllocation(allocationId);
  };

  const updateAllocationClick = async () => {
    if (!selectedAllocation) {
      alert("Please select allocation for update");
      return;
    }
    console.log("updating allocation", selectedAllocation.id);

    const expiry = new Date();
    expiry.setDate(expiry.getDate() + 30);

    //allocationId string,size, expiry int64,lock int64, isImmutable, updateTerms bool,addBlobberId, removeBlobberId string
    const size = parseInt(allocationSize),
      expiryVal = Math.floor(expiry.getTime() / 1000),
      lock = 5000000000,
      updateTerms = true,
      addBlobberId = "",
      removeBlobberId = "";

    //Call updateAllocation method
    await updateAllocation(
      selectedAllocation.id,
      size,
      expiryVal,
      lock,
      updateTerms,
      addBlobberId,
      removeBlobberId
    );
  };

const getBlobberListForAllocation = async () => {
    const expiryDate = new Date();
    expiryDate.setDate(expiryDate.getDate() + 30);

    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;

    //Call getAllocationBlobbers method
    const blobberList = await getAllocationBlobbers(
      referredBlobberURLs,
      dataShards,
      parityShards,
      size,
      expiry,
      minReadPrice,
      maxReadPrice,
      minWritePrice,
      maxWritePrice
    );
    console.log("blobberList", blobberList);
    return blobberList;
  };

  const getAllocationBlobbersClick = async () => {
    await getBlobberListForAllocation();
  };

  const getBlobberIdsClick = async () => {
    //https://dev1.zus.network/sharder01/v1/screst/6dba10422e368813802877a85039d3985d96760ed844092319743fb3a76712d7/getblobbers
    //const blobberUrls = [];
    const blobberUrls = [
      "https://dev2.zus.network/blobber02",
      "https://dev1.zus.network/blobber02",
    ];
    //Call getBlobberIds method
    const blobberIds = await getBlobberIds(blobberUrls);
    console.log("blobberIds", blobberIds);
  };

  const getAllocationFromAuthTicketClick = async () => {
    //Call getAllocationFromAuthTicket method
    console.log("GetAllocFromAuthTicket", authTicket);
    const allocation = await getAllocationFromAuthTicket(authTicket);
    console.log("allocation", allocation);
  };

const createReadPoolClick = async () => {
    //Call createReadPool method
    const result = await createReadPool();
    console.log("result", result);
  };

  const getReadPoolInfoClick = async () => {
    //Call getReadPoolInfo method
    console.log("GetReadPoolInfo", clientId);
    const result = await getReadPoolInfo(clientId);
    console.log("result", result);
  };

  const lockWritePoolClick = async () => {
    //Call lockWritePool method
    const allocationId = selectedAllocation.id;
    console.log("LockWritePool", allocationId);
    //allocationId string, tokens string, fee string
    const result = await lockWritePool(allocationId, 1000, 10);
    console.log("result", result);
  };

  const decodeAuthTicketClick = async () => {
    //Call decodeAuthTicket method
    console.log("DecodeAuthTicket", authTicket);
    const result = await decodeAuthTicket(authTicket);
    console.log("result", result);
  };

  const greetClick = async () => {
    //Call Greeter method
    const greetMessage = Greeter("john doe");
    setMessage(greetMessage);
  };

  const selectAllocation = (allocation) => {
    setSelectedAllocation(allocation);
  };

const selectFile = (file) => {
    setSelectedFile(file);
    console.log("selected file", file);
  };

const showLogsClick = async () => {
    await showLogs();
  };

  const hideLogsClick = async () => {
    await hideLogs();
  };

Describing Code

Line 1 to 219 defines the following allocation functionalities for the web app :

  • initClick:Initialize SDK functionality on click.js-sdk function is called. Here await keyword tells that the async function stops the execution until the config data is fetched.

  • listAllocationsClick: List Allocations on mouse click . Retrieved via js-sdk function.

  • createAllocationClick :Create allocation on click.Allocation is created via js-sdk function. Hereawait keyword tells that the async create allocation function to stop the execution until the allocation config is provided . config constant provides configuration for the allocation.

  • createAllocationWithBlobbersClick: Create allocation on a specific set /preferred blobbers.The blobber list is fetched via getBlobberListforAllocation function .Js-sdk method is called.

  • getAllocationDetailsClick :Get Allocation details in web app by calling listAllocationsClick function defined above.

  • reloadAllocationClick : Reloads the allocation in web app by calling js-sdk method.

  • freezeAllocationClick : Freeze Allocation on click in web app by calling js-sdk method.Await execution until allocation id is provided.

  • cancelAllocationClick :Cancel Allocation on click .Functionality provided by js-sdk function.

  • updateAllocationClick : Update Allocation configuration.Functionality provided by js-sdk method .Execution of updateAllocation method is awaited until updated allocation config is provided in term of allocation expiry or size.

  • getBlobberListForAllocation: Get list of blobbers available to host allocation.Calls js-sdk method.

  • getAllocationBlobbersClick :Get Blobbers for Allocation .awaits execution of getBlobberListForAllocation function specified above.

  • getBlobberIdsClick :Get blobber ID's on click.Calls js-sdk method .

  • getAllocationFromAuthTicketClick : Get Allocation with AuthTicket.Calls js-sdk .

  • createReadPoolClick : Create Read Pool for Storage SC. Calls js-sdk method

  • getReadPoolInfoClick: Get Read pool information.Calls js-sdk method.

  • lockWritePoolClick: Lock Tokens into Write Pool. Calls js-sdk method.

  • getBlobbersClick: Get Blobbers for honoring allocation. Calls js-sdk method.

  • decodeAuthTicket: A function for decoding AuthTicket generated by file share. Calls js-sdk method.

  • greetClick: A function for displaying a greeting message.

  • selectAllocation: A helper function for setting allocation.

  • selectFile: A helper function for selecting file for operations.

  • showLogs: Show logs for web app functionalities.Calls js-sdk method.

  • hideLogs: Hide logs for web app functionalities. Calls js-sdk method

cancelAllocation
init
listAllocations
createAllocation
createAllocationWithBlobbers
reloadAllocation
freezeAllocation
updateAllocation
getAllocationBlobbers
getBlobberIds
getAllocationFromAuthTicket
createReadPool
getReadPoolInfo
lockWritePool
getBlobbers
decodeAuthTicket
showLogs
hideLogs