diff --git a/Cargo.lock b/Cargo.lock
index b2bf3f6265e18..dab1f0a718e94 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -5706,6 +5706,7 @@ dependencies = [
"sp-blockchain 2.0.0",
"sp-core 2.0.0",
"sp-io 2.0.0",
+ "sp-offchain 2.0.0",
"sp-rpc 2.0.0",
"sp-runtime 2.0.0",
"sp-session 2.0.0",
diff --git a/client/rpc-api/src/lib.rs b/client/rpc-api/src/lib.rs
index c9306f2cddb79..8ad2d94bfd271 100644
--- a/client/rpc-api/src/lib.rs
+++ b/client/rpc-api/src/lib.rs
@@ -30,5 +30,6 @@ pub use helpers::Receiver;
pub mod author;
pub mod chain;
+pub mod offchain;
pub mod state;
pub mod system;
diff --git a/client/rpc-api/src/offchain/error.rs b/client/rpc-api/src/offchain/error.rs
new file mode 100644
index 0000000000000..c28a2a2f3911d
--- /dev/null
+++ b/client/rpc-api/src/offchain/error.rs
@@ -0,0 +1,51 @@
+// Copyright 2020 Parity Technologies (UK) Ltd.
+// This file is part of Substrate.
+
+// Substrate is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Substrate is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Substrate. If not, see .
+
+//! Offchain RPC errors.
+
+use jsonrpc_core as rpc;
+
+/// Offchain RPC Result type.
+pub type Result = std::result::Result;
+
+/// Offchain RPC errors.
+#[derive(Debug, derive_more::Display, derive_more::From)]
+pub enum Error {
+ /// Unavailable storage kind error.
+ #[display(fmt="This storage kind is not available yet.")]
+ UnavailableStorageKind,
+}
+
+impl std::error::Error for Error {
+ fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
+ None
+ }
+}
+
+/// Base error code for all offchain errors.
+const BASE_ERROR: i64 = 5000;
+
+impl From for rpc::Error {
+ fn from(e: Error) -> Self {
+ match e {
+ Error::UnavailableStorageKind => rpc::Error {
+ code: rpc::ErrorCode::ServerError(BASE_ERROR + 1),
+ message: "This storage kind is not available yet" .into(),
+ data: None,
+ },
+ }
+ }
+}
diff --git a/client/rpc-api/src/offchain/mod.rs b/client/rpc-api/src/offchain/mod.rs
new file mode 100644
index 0000000000000..bbe466ff5994d
--- /dev/null
+++ b/client/rpc-api/src/offchain/mod.rs
@@ -0,0 +1,37 @@
+// Copyright 2020 Parity Technologies (UK) Ltd.
+// This file is part of Substrate.
+
+// Substrate is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Substrate is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Substrate. If not, see .
+
+//! Substrate offchain API.
+
+pub mod error;
+
+use jsonrpc_derive::rpc;
+use self::error::Result;
+use sp_core::{Bytes, offchain::StorageKind};
+
+pub use self::gen_client::Client as OffchainClient;
+
+/// Substrate offchain RPC API
+#[rpc]
+pub trait OffchainApi {
+ /// Set offchain local storage under given key and prefix.
+ #[rpc(name = "offchain_localStorageSet")]
+ fn set_local_storage(&self, kind: StorageKind, key: Bytes, value: Bytes) -> Result<()>;
+
+ /// Get offchain local storage under given key and prefix.
+ #[rpc(name = "offchain_localStorageGet")]
+ fn get_local_storage(&self, kind: StorageKind, key: Bytes) -> Result