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 Node Operators
    • 🖥️Requirements
    • 🚀Witnet Node Quick Start Guide (Docker)
    • 🔎Next steps
    • 📄CLI Reference
    • 🤓Advanced Setups
      • Run Witnet as a systemd service
      • Run Witnet as a docker compose service
      • Paranoid mode (Witnet over proxies and Tor)
      • Configuration file
  • Witnet Node Developers
    • 🏗️Integration Guide
      • Node API Reference
      • Wallet API Reference
    • 🗜️Compile witnet-rust from Source Code
Powered by GitBook
On this page
  • WitnetRandomness contract
  • IWitnetRandomness interface
  • Clonable base contract
  • UsingWitnet base contract
  • WitnetRequestRandomness contract
  • IWitnetRequest interface
  • WitnetRequestMalleableBase base contract
  • Clonable base contract
  • Ownable base contract

Was this helpful?

Edit on GitHub
  1. Smart contracts developers
  2. Wit/Randomness

API Reference

PreviousCode ExamplesNextMulti-chain Addresses

Last updated 1 year ago

Was this helpful?

WitnetRandomness contract

IWitnetRandomness interface

Functions defined within the interface:

Function

Description

estimateRandomizeFee(uint256)

Returns amount of wei required to be paid as a fee when requesting randomization with a transaction gas price as the one given.

getRandomizeData(uint256)

Retrieves data of a randomization request that got successfully posted to the WRB within a given block. Returns zero values if no randomness request was actually posted within a given block.

getRandomnessAfter(uint256)

Retrieves the randomness generated upon solving a request that was posted within a given block, if any, or to the first request posted after that block, otherwise. Should the intended request happen to be finalized with errors on the Witnet oracle network side, this function will recursively try to return randomness from the next non-faulty randomization request found in storage, if any. Fails if: (a) no randomize() was not called in either the given block, or afterwards; (b) a request posted in/after given block does exist, but no result has been provided yet; or (c), all requests in/after the given block were solved with errors.

getRandomnessNextBlock(uint256)

Tells what is the number of the next block in which a randomization request was posted after the given one.

getRandomnessPrevBlock(uint256)

Gets previous block in which a randomness request was posted before the given one.

isRandomized(uint256)

Returns true only when the randomness request that got posted within given block was already reported back from the Witnet oracle, either successfully or with an error of any kind.

latestRandomizeBlock()

Returns latest block in which a randomness request got sucessfully posted to the WRB.

random(uint32,uint256,uint256)

Generates a pseudo-random number uniformly distributed within the range [0 .. _range), by using the given _nonce value and the randomness returned by getRandomnessAfter(_block). Fails under the same conditions as getRandomnessAfter(uint256) does.

random(uint32,uint256,bytes32)

Generates a pseudo-random number uniformly distributed within the range [0 .. _range), by using the given _nonce value and the given _seed as a source of entropy.

randomize() payable

Requests the Witnet oracle to generate an EVM-agnostic and trustless source of randomness. Only one randomness request per block will be actually posted to the WRB. Should there already be a posted request within current block, it will try to upgrade Witnet fee of current's block randomness request according to current gas price. In both cases, all unused funds shall be transfered back to the tx sender.

upgradeRandomizeFee(uint256) payable

Increases Witnet fee related to a pending-to-be-solved randomness request, as much as it may be required in proportion to how much bigger the current tx.gasprice is with respect the highest gas price that was paid in either previous fee upgrades, or when the given randomness request was posted. All unused funds shall be transferred back to the msg.sender.

witnetRandomnessRequest()

Clonable base contract

Function

Description

cloned()

Tells whether this contract is a clone of another (i.e. self())

clone()

Deploys and returns the address of a minimal proxy clone that replicates contract behaviour while using its own EVM storage.

cloneDeterministic(bytes32)

Deploys and returns the address of a minimal proxy clone that replicates contract behaviour while using its own EVM storage. This function uses the CREATE2 opcode and a _salt to deterministically deploy the clone. Using the same _salt multiple times will revert, since no contract can be deployed more than once at the same address.

self()

Returns the address of the underlying logic implementation contract.

UsingWitnet base contract

Function

Description

witnet()

WitnetRequestRandomness contract

IWitnetRequest interface

Function

Description

bytecode()

hash()

Returns the SHA256 hash of the bytecode().

WitnetRequestMalleableBase base contract

Function

Description

setWitnessingCollateral(uint64)

setWitnessingFees(uint64,uint64)

setWitnessingQuorum(uint8,uint8)

template()

Returns bytecode of the immutable RAD (Retrieve-Attest-Delivery) script's bytecode. Encoded using Protocol Buffers.

totalWitnessingCollateral()

Returns total amount of nanowits that witnessing nodes will need to collateralize all together.

totalWitnessingFee()

Returns total amount of nanowits that will have to be paid in total for this request to be solved.

witnessingParams()

Returns witnessing parameters of current Witnet Data Request.

Clonable base contract

Function

Description

cloned()

Tells whether this contract is a clone of another (i.e. self())

clone()

Deploys and returns the address of a minimal proxy clone that replicates contract behaviour while using its own EVM storage.

cloneDeterministic(bytes32)

Deploys and returns the address of a minimal proxy clone that replicates contract behaviour while using its own EVM storage. This function uses the CREATE2 opcode and a _salt to deterministically deploy the clone. Using the same _salt multiple times will revert, since no contract can be deployed more than once at the same address.

self()

Returns the address of the underlying logic implementation contract.

Ownable base contract

Function

Description

owner()

Tells who the current owner of this contract is. Owner may only modify the witnessing parameters of the contained Witnet Data Request, not the actual RAD (Retrieval-Attest-Deliver) script to be executed by Witnet nodes when solving the Data Request. Ownership can only be transferred by current owner. Ownership of this Data Request can only be gained by cloning the WitnetRandomness contract.

Returns address to the contract that is being used for requesting new randomness to the Witnet oracle.

Public functions inherited from the abstract pattern:

Public function inherited from the abstract contract:

Returns the immutable address of the that interacts with the Witnet oracle's sidechain, for both posting new data requests and receiving results from it.

Functions defined within the interface:

The Witnet Data Request reflecting the that will be processed by the Witnet oracle on every single price update. The returned bytes array is encoded using Protocol Buffers.

Public and restricted functions inherited from the abstract contract:

Sets amount of nanowits that a witness solving the request will be required to collateralize in the commitment transaction. Only callable by the , if any.

Specifies how much you want to pay for rewarding each of the Witnet nodes: (a) amount of nanowits that every request-solving witness will be rewarded with; (b) amount of nanowits that will be earned by Witnet miners for each each valid commit/reveal transaction they include in a block. Only callable by the , if any.

Sets how many Witnet nodes will be "hired" for resolving the request: (a) number of witnesses required to be involved for solving this Witnet Data Request; (b) threshold percentage for aborting resolution of a request if the witnessing nodes did not arrive to a broad consensus. Only callable by the , if any.

Public functions inherited from the abstract pattern:

Public function inherited from the abstract pattern:

🎲
IWitnetRandomness
Clonable
UsingWitnet
IWitnetRequest
WitnetRequestMalleableBase
Clonable
Ownable
RADON script
Witnet Request Board
WitnetRequestRandomness
owner()
owner()
owner()