Oracles provide blockchain applications access to off-chain information such as asset prices, and verifiable random numbers. Oracles allow blockchain applications to react to real-world events such as a price drop in collateral or the winner of a sporting event. Oracles typically rely on a trusted off-chain node to provide them with the correct data. This example oracle provides price data about a specific asset, and assumes a decimal precision of 1e9.
More information can be found in the specification.
The project consists of an oracle smart contract and an oracle node which interacts with the oracle.
oracle
├── project
│ ├── contracts
│ │ └── oracle-contract
│ │ ├── src/main.sw
│ │ └── tests/harness.rs
│ ├── oracle-node
│ │ ├── src/main.rs
│ │ └── tests/harness.rs
│ ├── README.md
│ └── SPECIFICATION.md
├── ui
│ ├── README.md
│ └── SPECIFICATION.md
└── README.md
TODO: The user interface does not currently exist therefore its README.md and SPECIFICATION.md are empty.
The project can be started by executing the following steps:
-
Change into the
Oracle
directory.cd <path>/sway-applications/oracle/<you are here>
-
Copy and paste the
.env.example
file into a new file called.env
.cp project/oracle-node/.env.example project/oracle-node/.env
-
In the newly copied
.env
file there is a variableAPI_URL
which ends with<your api key here>
. This section should be replaced with your API key. You can read more about this project's environment variables here -
Start a local
fuel-core
instance.fuel-core run --chain project/oracle-node/.chainConfig.json
This spins up and configures the local
fuel-core
instance with the variables specified in.chainConfig.json
. -
Build the Oracle contract.
forc build --locked
-
Deploy the Oracle contract.
forc-deploy --path project/contracts/oracle-contract --node-url localhost:4000 --unsigned
This will allow the node to interact with the oracle contract deployed to our local
fuel-core
instance.Note: Double check that the contract ID is the ID in the
.env
file. -
Start the Oracle node.
cargo run
Name | Description |
---|---|
API_URL | The URL the node uses to fetch the latest price for the asset tracked by the oracle. This oracle node relies on an external 3rd-party service to get price information to provide to the oracle contract. We do not endorse this service neither are we affiliated with them in any way. We only use the service for demonstration purposes. If you wish to run the node you can sign-up for a free api key here. If you wish to use another pricing api service feel free to replace API_URL entirely. |
ORACLE_CONTRACT_ID | Deterministic contract id of the oracle contract deployed in step 5. |
WALLET_SECRET | Private key of the first deterministic wallet provided by the fuels-rs sdk. This private key correspondes to the owner address specified in the oracle contract's Forc.toml . This address is also configured in step 4 to have the maximum amount of the BASE_ASSET. |
FUEL_PROVIDER_URL | Fuel-core network url normally set as http://localhost:4000/graphql for development. |
In order to run the subsequent commands change into the following directory /path/to/oracle/project/<here>
.
forc build --locked
Before running the tests the programs must be compiled with the command above.
cargo test --locked