Skip to content

machinefi/o3-ws-demo-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OPTION 3 INTEGRATION TEMPLATE

An template for integration of 3P API with W3bstream protocol

Table of Contents

Prerequisites

Before you begin, there are several prerequisites that must be met:

NFT URI

This step is optional, you can use the provided NFTs URIs, but if you want to use your own, please follow the instructions below.

You will need to upload one image and one metadata JSON file for the ERC721 Device SBT. For the ERC1155 Rewards - one image along with its corresponding metadata JSON file to represent the Rewards for completed training sessions.

Upload your NFT images and the corresponding metadata to a file storage of your choice or use a script in nft directory that will upload files to Arweave via Bundlr:

  • After cloning the repo navigate to nft directory and run npm i
  • In assets subdir you can find images for SBT and Rewards NFTs. You can update images with your own, but don't forget to update config file in src/config
  • Create .env file and add your PRIVATE_KEY (The account will be used to pay Bundlr fees with testnet tokens, please make sure to top up the corresponding account with some Matic tokens, link to faucet)
  • Run npm run upload
  • You'll find NFT URIs in nft/uploads.json (you'll need them at Step 2)
  • If funding while uploading fails, you can manually run fund script first npm run fund, it will fund your account with 0.1 MATIC

Project Setup and Execution Instructions

Follow the steps below to set up and run the project.

Step 1: Repository Cloning and Dependency Installation

  • Begin by clicking "use this template" which houses three directories: adapter, applet and blockchain.
  • Install the necessary dependencies by running npm i.

Step 2: Blockchain Environment Preparation

  • In the blockchain directory, create a .env file. Populate this file with the contents of .env.template.
  • Provide your PRIVATE_KEY that will be responsible for contract deployment and access control tasks.
  • Update the SBT_URI and REWARDS_URI variables in the .env file as per your setup (see NFT URI).
  • Opitional: update contract names SBT_CONTRACT_NAME and REWARDS_CONTRACT_NAME
  • The OPERATOR_ADDRESS will be acquired in the subsequent step.
  • Compile the contracts and generate contract types by running npm run compile.
  • Ensure everything is working by running npm run test.
  • Deploy your contracts by executing npm run deploy:testnet.

Step 3: Applet Modification

  • In the applet/wsproject.json file, change the project name from "drive_to_earn" to your preferred name, as well as update tables schemas, env variables and event routings if needed.
  • Update applets in applet/assembly/handlers directory to match your project needs
  • Compile the AssemblyScript code by navigating to the applet directory and running npm run asbuild.
  • Import the modified project into the W3bstream studio. Use applet/wsproject.json as the Project file and applet/build/release.wasm as the Wasm file.
  • Send a test message in Log.
  • Boost the operator address with Testnet IOTX token. The operator address can be found in Settings. An estimated 5 IOTX should suffice.

Step 4: Blockchain Environment Adjustment

  • Return to the blockchain directory and update the OPERATOR_ADDRESS in your .env file.
  • Run npx hardhat grant-sbt-minter --network testnet to assign the SBT minter role to the W3bstream operator.
  • Run npx hardhat grant-rewards-minter --network testnet to assign the Rewards NFT minter role to the W3bstream operator.

Step 5: Adapter Configuration

  • Create a new file named .env.local and populate it with the variables from .env.template.
  • Navigate to Account Settings in the studio interface to create an API key with Publisher and Event read and write persmisisons and update API_TOKEN in .env.local.
  • NEXTAUTH_SECRET can be aquired in Vercel secret generator
  • Find the HTTP_ROUTE under Events.
  • Start the client by running npm run dev and navigate to localhost:3000 in your web browser.
  • Follow the on-screen instructions to register your device and claim your SBT.
  • Sync the 3P Devices data and then recheck the studio db and proceed to claim your rewards.
  • Import the NFTs into Metamask.

Congratulations, you have successfully set up and run your project!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published