Examples of interacting with a Polkadot node using Rust

Overview

Examples of interacting with a Polkadot node

Some examples of using JSON RPC to interact with a Polkadot node, working up to manually building and submitting a balance transfer.

To run these examples, first start up a local Polkadot node (which we'll be interacting with):

# Clone the polkadot repo:
git clone https://github.com/paritytech/polkadot.git
# This is the commit I used (the examples will likely break as master is updated):
git checkout f3f83e3f9db049f981066b3a94fa17cad673299f
# Start up a polkadot dev node on your machine:
cargo run -- --tmp --dev

Once you have this node running, in another terminal, pick an example you'd like to run from the src/bin folder and run it like so:

cargo run --bin 01_basic

Note that the balance transfer example expects a fresh dev node (the transaction has a nonce which means it can't be executed more than once). Just restart the Polkadot node to get back to a fresh state.

The examples are well commented, so check them out to find out more!

One really useful tip for debugging what is happening is to visit https://polkadot.js.org/apps, and point it at your local node (click top left corner and in the "development" tab, point it to the node at ws://127.0.0.1:9944). Using this, you can see the balance transfer in example 05 take place, and compare other results with the actual node state.

You might also like...
A generic Rust based Bigtable connection library implemented using gRPC

A generic Rust based Bigtable connection library refactored out the solana mono-repo so that can be shared for different applications.

An example of a common Wi-Fi set up scenario on ESP32 using Rust

UTC IoT fetcher This repo is an example of how to configure a Wi-Fi client on an ESP32-based IoT device using an external device connection to the int

A simple API gateway written in Rust, using the Hyper and Reqwest libraries.

API Gateway A simple API gateway written in Rust, using the Hyper and Reqwest libraries. This gateway can be used to forward requests to different bac

Download a file using multiple threads in parallel for faster download speeds.

multidl Download a file using multiple threads in parallel for faster download speeds. Uses 0 external dependencies. Usage Usage: multidl [--help] ADD

Tunnel TCP traffic through SOCKS5 or HTTP using a TUN interface.

tun2proxy Tunnel TCP traffic through SOCKS5 or HTTP on Linux. Authentication not yet supported. Error handling incomplete and too restrictive. Build C

The Graph is a protocol for building decentralized applications (dApps) quickly on Ethereum and IPFS using GraphQL.

Graph Node The Graph is a protocol for building decentralized applications (dApps) quickly on Ethereum and IPFS using GraphQL. Graph Node is an open s

Private swaps for Secret Network using a private entropy pool & differential privacy.

WIP SecretSwap: Anon Edition Private swaps for Secret Network! Uses private entropy pool for differential privacy when reporting pools sizes. Swap amo

Proxy sentry request to a sentry server using a tunnel/proxy endpoint

Sentry Tunnel This is a proxy that forwards tunneled sentry requests to the real sentry server. The implementation is based on the explanation provide

YAC (Yac is Another Chat) is an example of Chat using WebSocket.

YAC (Yac is Another Chat) is an example of Chat using WebSocket. Because often the example you find in internet are "not so production ready", I would like to try to implement something more robust.

Comments
  • Add Storage Iterator example for Double Map

    Add Storage Iterator example for Double Map

    The example iterates over the XcmPallet's VersionNotifiers keys while decoding the raw bytes to user-friendly representations. The example also obtains the value stored in the node at those locations.

    To achieve this XCM interaction a WebSocket client is introduced, running against a local node. Other examples are updated with the latest version of substrate.


    VersionNotifiers storage key: 0x1405f2411d0af5a7ff397e7c9dc68d19db8f48f20e9ff76107a081bb8a607cd5
    Obtained keys:
    Key: 0x1405f2411d0af5a7ff397e7c9dc68d19db8f48f20e9ff76107a081bb8a607cd59eb2dcce60f37a270200000005dd59ff1333ed58157a7deed14d96af01000100511f
         bytes[ 0..16]: 0x1405f2411d0af5a7ff397e7c9dc68d19 == twox_128("XcmPallet")
         bytes[16..32]: 0xdb8f48f20e9ff76107a081bb8a607cd5 == twox_128("VersionNotifiers")
         bytes[32..40]: 0x9eb2dcce60f37a27                 == twox_64(first key)
         bytes[40..44]: 0x02000000                         == first key - XcmVersion: 2
         bytes[44..60]: 0x05dd59ff1333ed58157a7deed14d96af == blake2_128(second key)
         bytes[60..  ]: 0x01000100511f                     == second key - VersionedMultiLocation: V1(MultiLocation { parents: 0, interior: X1(Parachain(2004)) })
      Value: 4
    
    Key: 0x1405f2411d0af5a7ff397e7c9dc68d19db8f48f20e9ff76107a081bb8a607cd59eb2dcce60f37a2702000000100d8a96165380224fcebf540672e38c01000100411f
         bytes[ 0..16]: 0x1405f2411d0af5a7ff397e7c9dc68d19 == twox_128("XcmPallet")
         bytes[16..32]: 0xdb8f48f20e9ff76107a081bb8a607cd5 == twox_128("VersionNotifiers")
         bytes[32..40]: 0x9eb2dcce60f37a27                 == twox_64(first key)
         bytes[40..44]: 0x02000000                         == first key - XcmVersion: 2
         bytes[44..60]: 0x100d8a96165380224fcebf540672e38c == blake2_128(second key)
         bytes[60..  ]: 0x01000100411f                     == second key - VersionedMultiLocation: V1(MultiLocation { parents: 0, interior: X1(Parachain(2000)) })
      Value: 7
    
    Key: 0x1405f2411d0af5a7ff397e7c9dc68d19db8f48f20e9ff76107a081bb8a607cd59eb2dcce60f37a27020000004e764be91a94f8c0b1516f7775b719ea01000100a10f
         bytes[ 0..16]: 0x1405f2411d0af5a7ff397e7c9dc68d19 == twox_128("XcmPallet")
         bytes[16..32]: 0xdb8f48f20e9ff76107a081bb8a607cd5 == twox_128("VersionNotifiers")
         bytes[32..40]: 0x9eb2dcce60f37a27                 == twox_64(first key)
         bytes[40..44]: 0x02000000                         == first key - XcmVersion: 2
         bytes[44..60]: 0x4e764be91a94f8c0b1516f7775b719ea == blake2_128(second key)
         bytes[60..  ]: 0x01000100a10f                     == second key - VersionedMultiLocation: V1(MultiLocation { parents: 0, interior: X1(Parachain(1000)) })
      Value: 2
    
    Key: 0x1405f2411d0af5a7ff397e7c9dc68d19db8f48f20e9ff76107a081bb8a607cd59eb2dcce60f37a270200000077250378cce57ae600f6c271b88c7649010001000920
         bytes[ 0..16]: 0x1405f2411d0af5a7ff397e7c9dc68d19 == twox_128("XcmPallet")
         bytes[16..32]: 0xdb8f48f20e9ff76107a081bb8a607cd5 == twox_128("VersionNotifiers")
         bytes[32..40]: 0x9eb2dcce60f37a27                 == twox_64(first key)
         bytes[40..44]: 0x02000000                         == first key - XcmVersion: 2
         bytes[44..60]: 0x77250378cce57ae600f6c271b88c7649 == blake2_128(second key)
         bytes[60..  ]: 0x010001000920                     == second key - VersionedMultiLocation: V1(MultiLocation { parents: 0, interior: X1(Parachain(2050)) })
      Value: 6
    
    Key: 0x1405f2411d0af5a7ff397e7c9dc68d19db8f48f20e9ff76107a081bb8a607cd59eb2dcce60f37a27020000007c40b0b99e93a82fa5901740fd6c0eba01000100711f
         bytes[ 0..16]: 0x1405f2411d0af5a7ff397e7c9dc68d19 == twox_128("XcmPallet")
         bytes[16..32]: 0xdb8f48f20e9ff76107a081bb8a607cd5 == twox_128("VersionNotifiers")
         bytes[32..40]: 0x9eb2dcce60f37a27                 == twox_64(first key)
         bytes[40..44]: 0x02000000                         == first key - XcmVersion: 2
         bytes[44..60]: 0x7c40b0b99e93a82fa5901740fd6c0eba == blake2_128(second key)
         bytes[60..  ]: 0x01000100711f                     == second key - VersionedMultiLocation: V1(MultiLocation { parents: 0, interior: X1(Parachain(2012)) })
      Value: 3
    
    Key: 0x1405f2411d0af5a7ff397e7c9dc68d19db8f48f20e9ff76107a081bb8a607cd59eb2dcce60f37a2702000000b3004529114de762981310e9a525ec1901000100690a
         bytes[ 0..16]: 0x1405f2411d0af5a7ff397e7c9dc68d19 == twox_128("XcmPallet")
         bytes[16..32]: 0xdb8f48f20e9ff76107a081bb8a607cd5 == twox_128("VersionNotifiers")
         bytes[32..40]: 0x9eb2dcce60f37a27                 == twox_64(first key)
         bytes[40..44]: 0x02000000                         == first key - XcmVersion: 2
         bytes[44..60]: 0xb3004529114de762981310e9a525ec19 == blake2_128(second key)
         bytes[60..  ]: 0x01000100690a                     == second key - VersionedMultiLocation: V1(MultiLocation { parents: 0, interior: X1(Parachain(666)) })
      Value: 5
    
    Key: 0x1405f2411d0af5a7ff397e7c9dc68d19db8f48f20e9ff76107a081bb8a607cd59eb2dcce60f37a2702000000de763eb59c21d5cf088fab93114f368b01000100591f
         bytes[ 0..16]: 0x1405f2411d0af5a7ff397e7c9dc68d19 == twox_128("XcmPallet")
         bytes[16..32]: 0xdb8f48f20e9ff76107a081bb8a607cd5 == twox_128("VersionNotifiers")
         bytes[32..40]: 0x9eb2dcce60f37a27                 == twox_64(first key)
         bytes[40..44]: 0x02000000                         == first key - XcmVersion: 2
         bytes[44..60]: 0xde763eb59c21d5cf088fab93114f368b == blake2_128(second key)
         bytes[60..  ]: 0x01000100591f                     == second key - VersionedMultiLocation: V1(MultiLocation { parents: 0, interior: X1(Parachain(2006)) })
      Value: 8
    
    opened by lexnv 1
  • Bump tokio from 1.18.2 to 1.18.4

    Bump tokio from 1.18.2 to 1.18.4

    Bumps tokio from 1.18.2 to 1.18.4.

    Release notes

    Sourced from tokio's releases.

    Tokio v1.18.3

    1.18.3 (September 27, 2022)

    This release removes the dependency on the once_cell crate to restore the MSRV of the 1.18.x LTS release. (#5048)

    #5048: tokio-rs/tokio#5048

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • Bump thread_local from 1.1.3 to 1.1.4

    Bump thread_local from 1.1.3 to 1.1.4

    Bumps thread_local from 1.1.3 to 1.1.4.

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
Owner
Parity Technologies
Solutions for a trust-free world
Parity Technologies
Astar Network is an interoperable blockchain based the Substrate framework and the hub for dApps within the Polkadot Ecosystem

Astar Network is an interoperable blockchain based the Substrate framework and the hub for dApps within the Polkadot Ecosystem. With Astar Network and

Astar Network (Plasm) 43 Dec 14, 2022
A set of Rust crates for interacting with the Matrix chat network.

Ruma – Your home in Matrix. A set of Rust crates (libraries) for interacting with the Matrix chat network. website • chat • documentation (unstable) G

Ruma 441 Dec 26, 2022
Unix dgram, seqpacket, etc binding for Node.js.

node-unix-socket node-unix-socket allows you to use some nonblocking unix sockets that are currently not supported by Node.js native modules, includin

Bytedance Inc. 40 Jun 28, 2023
Cross-platform, low level networking using the Rust programming language.

libpnet Linux ∪ OS X Build Status: Windows Build Status: Discussion and support: #libpnet on freenode / #rust-networking on irc.mozilla.org / #rust on

null 1.8k Jan 6, 2023
Simple VPN implemented using rust

fubuki Simple VPN implemented using rust fubuki是类似与tincVPN的简单组网工具 不支持对等NAT 支持的平台: Windows Linux 工作机制 它由一台拥有公网IP的服务器来维持各个内网客户端的实际地址映射,在客户端和客户端之间实现P2P通信

XTY 84 Dec 31, 2022
Implementing Bendersnatch curve using Arkwork's framework in Rust.

This is a reference implementation of Bendersnatch curve using Arkwork's framework in Rust. The spec of the curve is available here. There was also a Python reference implementation here.

zhenfei 8 Jun 18, 2022
WIP / POC for using the BL602 wifi blob from Rust

BL602 Wifi Rust This is work in progress and currently more a proof of concept. The code is awfully hacked together - just enough to make it work. It

Björn Quentin 23 Sep 15, 2022
Modrinth API is a simple library for using Modrinth's API in Rust projects

Ferinth is a simple library for using the Modrinth API in Rust projects. It uses reqwest as its HTTP(S) client and deserialises responses to typed structs using serde.

null 20 Dec 8, 2022
RusTCP is an attempt to rewrite some of the PyTCP stack functionality using Rust language.

RusTCP is an attempt to rewrite some of the PyTCP stack functionality using Rust language. Currently, the main goal of this project is to create a stable IPv6 platform that could be used to facilitate the process of labing the SRv6 technology.

Sebastian Majewski 3 Dec 5, 2022
WIP / POC for using the ESP32C3 wifi drivers in bare-metal Rust

Wifi on ESP32C3 (on bare-metal Rust) About This is experimental and work-in-progress! You are welcome to contribute but probably shouldn't use this fo

Björn Quentin 135 Jan 2, 2023