Skip to content
Prev Previous commit
Next Next commit
Fix fetch remote
  • Loading branch information
ascjones committed Oct 22, 2021
commit d1566e869be6c5baaf22c5c8fec15af9912578f5
48 changes: 8 additions & 40 deletions examples/fetch_remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,56 +14,24 @@
// You should have received a copy of the GNU General Public License
// along with subxt. If not, see <http://www.gnu.org/licenses/>.

use sp_runtime::traits::BlakeTwo256;
use subxt::{
ClientBuilder,
Config,
};
use subxt::ClientBuilder;

#[subxt::subxt(runtime_metadata_path = "tests/integration/node_runtime.scale")]
pub mod node_runtime {
#[subxt(substitute_type = "sp_core::crypto::AccountId32")]
use sp_core::crypto::AccountId32;
#[subxt(substitute_type = "primitive_types::H256")]
use sp_core::H256;
#[subxt(substitute_type = "sp_runtime::multiaddress::MultiAddress")]
use sp_runtime::MultiAddress;

#[subxt(substitute_type = "sp_arithmetic::per_things::Perbill")]
use sp_arithmetic::per_things::Perbill;
#[subxt(substitute_type = "sp_arithmetic::per_things::Perquintill")]
use sp_arithmetic::per_things::Perquintill;
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct KusamaRuntime;

impl Config for KusamaRuntime {
type Index = u32;
type BlockNumber = u32;
type Hash = sp_core::H256;
type Hashing = BlakeTwo256;
type AccountId = sp_runtime::AccountId32;
type Address = sp_runtime::MultiAddress<Self::AccountId, u32>;
type Header = sp_runtime::generic::Header<Self::BlockNumber, BlakeTwo256>;
type Extra = subxt::extrinsic::DefaultExtra<Self>;
type Signature = sp_runtime::MultiSignature;
type Extrinsic = sp_runtime::OpaqueExtrinsic;
type AccountData = node_runtime::system::storage::Account;
}
#[subxt::subxt(runtime_metadata_path = "examples/polkadot_metadata.scale")]
pub mod polkadot {}

#[async_std::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
env_logger::init();

let client = ClientBuilder::<KusamaRuntime>::new()
.set_url("wss://kusama-rpc.polkadot.io")
let api = ClientBuilder::new()
.set_url("wss://rpc.polkadot.io")
.build()
.await?;
.await?
.to_runtime_api::<polkadot::RuntimeApi<polkadot::DefaultConfig>>();

let block_number = 1;

let block_hash = client.block_hash(Some(block_number.into())).await?;
let block_hash = api.client.rpc().block_hash(Some(block_number.into())).await?;

if let Some(hash) = block_hash {
println!("Block hash for block number {}: {}", block_number, hash);
Expand Down