0

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?

1 Answer 1

2

You need to allow http requests.

https://github.com/paritytech/polkadot-sdk/blob/283d3cc5676417a29783786a41a01680d123f7bb/substrate/client/offchain/src/lib.rs#L112

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.