An template for integration of 3P API with W3bstream protocol
Before you begin, there are several prerequisites that must be met:
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 runnpm 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 insrc/config
- Create
.env
file and add yourPRIVATE_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
Follow the steps below to set up and run the project.
- Begin by clicking "use this template" which houses three directories:
adapter
,applet
andblockchain
. - Install the necessary dependencies by running
npm i
.
- 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
andREWARDS_URI
variables in the.env
file as per your setup (see NFT URI). - Opitional: update contract names
SBT_CONTRACT_NAME
andREWARDS_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
.
- 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 runningnpm run asbuild
. - Import the modified project into the W3bstream studio. Use
applet/wsproject.json
as theProject file
andapplet/build/release.wasm
as theWasm 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.
- Return to the
blockchain
directory and update theOPERATOR_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.
- 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 updateAPI_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!