Skip to content

Instantly share code, notes, and snippets.

@whoisdevd
Created September 4, 2022 08:59
Show Gist options
  • Save whoisdevd/1856d8e1b4358b85fbd9f72070121754 to your computer and use it in GitHub Desktop.
Save whoisdevd/1856d8e1b4358b85fbd9f72070121754 to your computer and use it in GitHub Desktop.
Health Planet - Smart Contract Usage

Health Planet - Fitness Application

Basic functions and their usage

function mintForUser (bytes32 userDetail) external onlyOwner; ==> This function is used to mint the NFT and connect that NFT to a particular user

function burnUserToken (bytes32 userDetail, uint tokenId) external onlyOwner ==> This function is used to burn the NFT and remove all the details for that user

function log(bytes32 userDetails, uint _calorieCount) external onlyOwner ==> Allow the operator (here the application) to log in calorie details for a particular user

function viewTotalLoggedDataPerUser (bytes32 userDetails) external view returns (uint) ==> Displays summation total logged calories till date

function viewLoggedDataPerUser (bytes32 userDetails) external view returns ==> Display total data logger by an user

function setUri (string memory _uri) external onlyOwner ==> Set the URI for the NFT

NOTE: function definitions and more details can be found in the smart contracts source code

Smart Contract Interaction Code

Download the Contract ABI (abi.json) form the source link in the following code from the following link https://rinkeby.etherscan.io/address/0xf5062263799094f1C89E8f988b002d01a1BA52C2#code

import { ethers } from "ethers";
import abi from "./abi.json";

let contract;

const contractAddress = "0xf5062263799094f1C89E8f988b002d01a1BA52C2";

export const providerHandler = async () => {
  const provider = new ethers.providers.Web3Provider(window.ethereum);
  const account = await provider.listAccounts();
  const address = account[0];
  const signer = provider.getSigner();
  contract = new ethers.Contract(contractAddress, abi, signer);
  return address;
};

//read functions

export const tokenDetails = async (id) => {
  const n = await contract.tokenDetails(id);
  return n.toNumber();
};

export const userLogDetails = async (id) => {
    const n = await contract.userLogDetails(id);
    return n;
};

export const currentTokenId = async () => {
    const n = await contract.currentTokenId();
    return n.toNumber();
};

export const totalUser = async () => {
    const n = await contract.totalUser();
    return n.toNumber();
};

export const mintForUser = async (userDetail) => {
    const n = await contract.mintForUser(userDetail);
    await n.wait();
    return n
};

export const burnUserToken = async (userDetail, tokenId) => {
    const n = await contract.burnUserToken(userDetail, tokenId);
    await n.wait();
    return n
};

export const log = async (userDetail, _calorieCount) => {
    const n = await contract.log(userDetail, _calorieCount);
    await n.wait();
    return n
};

export const viewTotalLoggedDataPerUser = async (userDetail) => {
    const n = await contract.viewTotalLoggedDataPerUser(userDetail);
    await n.wait();
    return n
};

export const viewLoggedDataPerUser = async (userDetail) => {
    const n = await contract.viewLoggedDataPerUser(userDetail);
    await n.wait();
    return n
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment