Request Offchain HTTP
Illustrates how to use an offchain worker to make HTTP requests.
Set a deadline and instantiate an HTTP request
let deadline = sp_io::offchain::timestamp().add(Duration::from_millis(2_000));let request = http::Request::get("https://min-api.cryptocompare.com/data/price?fsym=BTC&tsyms=USD"); let pending = request.deadline(deadline).send().map_err(|_| http::Error::IoError)?; let response = pending.try_wait(deadline).map_err(|_| http::Error::DeadlineReached)??;
Read and submit the response
Examples
Last updated