I am trying to use Substrate Offchain Worker. I implemented as mentioned here https://github.com/paritytech/polkadot-sdk/tree/master/substrate/frame/examples/offchain-worker.
I am using same sample
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)??;
if response.code != 200 {
log::warn!("Unexpected status code: {}", response.code);
return Err(http::Error::Unknown)
}
When I start my local parachain node with --offchain-worker always
, I get below error after each block production:
Evicting failed runtime instance error=Runtime panicked: Accessing a forbidden API: http_request_start. No: HTTP capability.
This URL https://min-api.cryptocompare.com/data/price?fsym=BTC&tsyms=USD
is working fine in my browser.
Can somebody please guide me what I am missing here?