LogoLogo
WebsiteDiscordTelegramTwitter
  • 🏠Witnet Oracle Docs
  • Introduction
    • ❓What is Witnet?
      • ⚙️Oracle Architecture
      • 🪙The Witnet Coin (Wit)
      • 👛Wallets
      • 🤔Frequently Asked Questions
      • 😎Awesome Witnet
    • 🚀Quick Tutorials
      • 📈Price Feeds
      • 🎲Randomness
      • 🌐APIs and HTTP GET/POST
      • ⛏️Mining Wit
  • Smart contracts developers
    • ⛓️Supported chains
    • 🔮Wit/Oracle
      • HTTP GET Requests in Solidity
      • HTTP POST Requests in Solidity
      • Query GraphQL APIs in Solidity
      • Dynamic Requests in Solidity
      • UsingWitnet Inheritance
      • API Reference
        • Solidity API
          • Solidity Contracts
            • WitnetRequestBoard
        • Javascript API
        • RADON API
          • RADON Type System
          • RADON Errors
      • Multi-chain Addresses
    • 💹Wit/Price Feeds
      • How To Use Witnet Price Feeds
      • Update Conditions
      • Code Examples
      • API Reference
      • Multi-chain Addresses
        • Arbitrum Price Feeds
        • Avalanche Price Feeds
        • Base Price Feeds
        • Boba Price Feeds
        • Celo Price Feeds
        • Conflux Price Feeds
        • Cronos Price Feeds
        • Dogechain Price Feeds
        • Elastos Price Feeds
        • Ethereum Price Feeds
        • Gnosis Chain Price Feeds
        • Kaia Price Feeds
        • Kava Price Feeds
        • KCC Price Feeds
        • Mantle Price Feeds
        • Meter Price Feeds
        • Metis Price Feeds
        • Moonbeam Price Feeds
        • OKX Price Feeds
        • Optimism Price Feeds
        • Polygon Price Feeds
        • Reef Price Feeds
        • Scroll Price Feeds
        • Syscoin Price Feeds
        • Ultron Price Feeds
        • Request new price feed or chain support
    • 🎲Wit/Randomness
      • Generating Randomness
      • WitnetRandomness Contract
      • Low-level Requests
      • Code Examples
      • API Reference
      • Multi-chain Addresses
    • 🏗️Guides
      • 📖Solidity Contracts
        • Appliances
          • 📃WitnetPriceFeeds
          • 📃WitnetRandomness
        • Core
          • 📃WitnetOracle
          • 📃WitnetRadonRegistry
          • 📃WitnetRequest
          • 📃WitnetRequestFactory
          • 📃WitnetRequestTemplate
        • Mockups
          • 📃UsingWitnet
          • 📃UsingWitnetRandomness
          • 📃UsingWitnetRequest
          • 📃UsingWitnetRequestTemplate
          • 📃WitnetRandomnessRequestConsumer
          • 📃WitnetRequestConsumer
          • 📃WitnetRequestTemplateConsumer
      • 🧙Solidity Wizard
    • 🎓Tutorials
      • Building a Satoshi/Wei custom price feed
  • Witnet SDK
    • 👋Introduction
    • 🚀Getting Started
    • 🏗️How-to Guides
      • Connect to a Wit/RPC provider
      • Query stake entries in Witnet
      • Manage Witnet wallets
      • Manage Witnet UTXOs
      • Manage Witnet transactions
    • 🎓Tutorials
    • 📚Reference Material
      • 🔌APIs
        • Wit/Node JSON-RPC API
  • Witnet Validators
    • 💻Node Requirements
    • 🚀Getting Started (Docker)
    • 🔎Next steps
    • 🤓Advanced Setups
      • Run node as a systemd service
      • Run node with docker compose
      • Paranoid mode (Witnet over proxies and Tor)
      • Configuration file
    • ⌨️CLI Reference
  • 🗜️Compile from Source Code
Powered by GitBook
On this page
  • Package @witnet/sdk
  • Prerequisites
  • Installation
  • Setting up the environment
  • Smoke tests

Was this helpful?

Edit on GitHub
  1. Witnet SDK

Getting Started

PreviousIntroductionNextHow-to Guides

Last updated 1 month ago

Was this helpful?

The Witnet SDK offers a comprehensive range of NPM packages tailored to various Web3 environments and programming languages, ensuring you have the right tools for your specific use case.

Witnet SDK packages

Javascript and Typescript developers willing to interact with the Witnet blockchain.

Developers willing to report notarized oracle queries from the Witnet blockchain into smart contracts in EVM-compatible chains, get smart contracts to build verifiable oracle queries on-chain, or pull them off from the Witnet blockchain. Embeds @witnet/sdk.

Devops and devs willing to leverage, query or autonomously report notarized price feed updates, subsidized or not by the Witnet Foundation. Embeds: @witnet/sdk and @witnet/sdk-solidity.

You don't need to run a Witnet node, stake $WIT coins, or pay subscription fees to use any of these packages, whatsoever. The Witnet SDK is totally open sourced and distributed under MIT license.

In certain back-end environments, though, you might prefer to run your own Witnet nodes as to avoid relying on third-party Wit/RPC providers.

Witnet is a totally and Proof-of-Stake blockchain, and the for running a node are surprisingly low. You don't even need to stake $WIT into your nodes if just willing to use them for transmitting transactions or fetching data from the blockchain. Becoming a Witnet validator could easily sustain the cost of running nodes, nonetheless. Learn how to setup, stake and run a Witnet node .


Package @witnet/sdk

Prerequisites

  • Node.js >=18.17.0

Installation

$ pnpm add @witnet/sdk
$ npm install --save @witnet/sdk
$ yarn add @witnet/sdk

Importing the SDK library

const { assets, utils, Witnet } = require('@witnet/sdk') 
import { assets, utils, Witnet } from '@witnet/sdk' }

Embedded binaries

This package embeds an executable that allows you to interact with the Witnet blockchain and even manage your own $WIT coins and Radon assets (i.e. customized oracle queries and web data sources), from the command line. It also allows dry-running oracle data queries, locally.

$ pnpm witnet --version
$ npx witnet --version
$ yarn witnet --version

Setting up the environment

Two environment variables are required to interact with the Witnet blockchain:

  • WITNET_SDK_PROVIDER_URL

  • WITNET_SDK_WALLET_MASTER_KEY

WITNET_SDK_PROVIDER_URL

URL of the Wit/RPC endpoint that will provide both information about the Witnet network, and the transmission of transactions signed in Javascript.

This URL can correspond to that of any validator or archive nodes in the Witnet network (as long as the corresponding http/rpc port is reachable), or any of the public-domain endpoints provided by the Witnet Foundation:

Pubiic Networks
Wit/RPC Providers
Network id
Description

Witnet Mainnet

https://rpc.witnet.io

0x9FED

Where Wit/oracle queries get notarized for real, and results forever stored into the Witnet blockchain. Transactions get paid in real $WIT coins.

Witnet Testnet

https://rpc-testnet.witnet.io

0x2845

Only for testing purposes. Transactions get paid in $TWIT coins with no market value.

If no otherwise specified, and no WITNET_RPC_PROVIDER is set in the environment, classes from the Javascript library will rely on https://rpc.witnet.io as default Wit/RPC provider.

WITNET_SDK_WALLET_MASTER_KEY

Master keys exported from myWitWallet get encrypted with a password.

Encrypted master keys requires the password to be specified in Javascript, or typed every time the CLI binary is asked to sign a transaction. If deemed necessary, decrypt master keys by following these steps:

  • Run $ npx witnet wallet decipher.

  • Copy the XPRV string exported from myWitWallet and paste it into the console.

  • Enter the password used when exporting the master key.

Smoke tests

Checklist
Commands

Verify the actual Witnet provider and network you're connecting to.

$ npx witnet network provider

The Wit/RPC provider should be operational and synced.

$ npx witnet network syncStatus

You should be able to operate with the same Witnet address/es as the one/s available on whatever app, or node, where the master key was imported from.

$ npx witnet wallet accounts

If using the Witnet Public Testnet for testing out transactions or notarization of oracle queries, please join the and ask for getting airdropped with some $TWIT testing coins for free.

In order to derive Witnet accounts, compose and sign transactions in Javascript, a valid private key in XPRV format must be provided, either , or from the or the wallet applications.

🚀
permissionless
requirements
here
Witnet Discord channel
exported from a Witnet node
myWitWallet
Sheikah
@witnet/sdk
@witnet/sdk-solidity
@witnet/sdk-price-feeds