JS Setup (ethers v6)

This page prepares your app to interact with the DecentralizedOracle using ethers v6. No deployment, governance, or meta info is covered here.

Prerequisites

  • Node 18+ (recommended)
  • ethers v6 in your project
  • RPC endpoint: https://bsc-dataseed.bnbchain.org (BNB Chain Mainnet)
  • Contract addresses (see Contract Addresses for details):
    • Oracle: 0xFA4595F636887CA28FCA3260486e44fdcc8c8A71
    • Token: 0x948d7a6f18511df422184360d1cd5d56f5be4444
  • Oracle ABI: see Oracle ABI page → ./abi.md

Install and basic wiring

pnpm add ethers
# or
npm i ethers

Create a provider, then a Contract instance using the oracle ABI.

import { JsonRpcProvider, Contract } from 'ethers'
import OracleArtifact from '../../../artifacts/contracts/FarmTruth.sol/DecentralizedOracle.json' // ABI also listed in ./abi.md

const rpc = 'https://bsc-dataseed.bnbchain.org'
const provider = new JsonRpcProvider(rpc)

const ORACLE_ADDRESS = '0xFA4595F636887CA28FCA3260486e44fdcc8c8A71'
const oracle = new Contract(ORACLE_ADDRESS, (OracleArtifact as any).abi, provider)

// Optional: code presence check to avoid BAD_DATA errors
const code = await provider.getCode(ORACLE_ADDRESS)
if (!code || code === '0x') throw new Error('No bytecode at ORACLE_ADDRESS')

If you need a signer (browser or server), attach it to the same ABI:

import { BrowserProvider, Contract } from 'ethers'
import OracleArtifact from '../../../artifacts/contracts/FarmTruth.sol/DecentralizedOracle.json' // ABI also listed in ./abi.md

const browser = new BrowserProvider((globalThis as any).ethereum)
const signer = await browser.getSigner()

const ORACLE_ADDRESS = '0xFA4595F636887CA28FCA3260486e44fdcc8c8A71'
const oracle = new Contract(ORACLE_ADDRESS, (OracleArtifact as any).abi, signer)

Read-only vs signer flows

  • Read-only: instantiate oracle with a provider to call view functions (e.g., getQueryDetails, getActiveQueriesCount).
  • Signer: instantiate oracle with a signer to submit transactions (e.g., createQuery, voteOnQuery, resolveQuery, claimRewards).

Navigate next:

  • Create a query → ./create
  • Vote on a query → ./vote
  • Resolve a query → ./resolve
  • Claim rewards → ./claim
  • Ties, extensions, slashing → ./ties-slashing
  • Pagination and listing → ./pagination
  • Reference snippets → ./snippets

Back to: