This repository contains all relevant project necessary to have polkadot and substrate chains interact with chainlink.
This is WIP and will evolve frequently.
Using pallet-chainlink
is fairly straightforward and requires a couple easy steps:
- add the correct dependency to your runtime
- use some of the pallet bundled functions
Update Cargo.toml
to reference pallet-chainlink
.
Add the following section:
[dependencies.chainlink]
default_features = false
package = 'pallet-chainlink'
And amend the std
section so that it shows like this:
std = [
... // all the existing pallets
'chainlink/std'
]
Edit lib.rs
to that it references pallet-chainlink
:
...
// Add the chainlink Trait
impl chainlink::Trait for Runtime {
type Event = Event;
}
...
// In construct_runtime!, add the pallet
...
construct_runtime!(
...
Chainlink: chainlink::{Module, Event<T>},
}
);
Add necessary use
declarations:
use chainlink::{Event, create_get_parse_request};
You can now deposit chainlink events:
Self::deposit_event(create_get_parse_request::<T>(who));
Those will be picked up by chainlink nodes that will in turn
See the full example for more details.
rust-toolchain
is used to make sure the correct rust version is used. Make sure to install the WASM target using:
rustup target add wasm32-unknown-unknown
substrate-node-example
shows off out to use pallet-chainlink
end-to-end.
To test:
- start the chain using
make run-chain
- start the frontend using
make run-front-end
You are now ready to send test requests and see the result being provided back by an Oracle (TBD).
const alice = ...;
const txHash = await api.tx.example
.sendRequest()
.signAndSend(alice);
console.log(`Submitted with hash ${txHash}`);
Make sure you add the following additional to Settings/Developer
section:
{"SpecIndex": "u32",
"RequestIdentifier": "u64",
"DataVersion": "u64"}
Then in Extrinsincs
, example
/ sendRequest
can be submitted.