Ankr Docs
Search…
Develop on Kusama
Ankr allows users to create their own Kusama relay chain APIs with a variety of options for request call limits, archived data, and more. Ankr’s novel cluster technology allows APIs to draw from multiple nodes, offering a more reliable experience for our users.

Get started on Kusama

  1. 1.
    Login or set up an account on app.ankr.com

Nodes Available on Ankr

  • Kusama Relay Chain

Networks Available on Ankr

  • Kusama Relay Mainnet

JSON RPC Methods

Kusama's approach to JSON-RPC methods is unique and not the same as the standard** **Ethereum JSON-RPC methods.
You can call the rpc_methods method to view the list of methods supported by Kusama.
View Substrate RPC client in Go documentation for calling RPC methods.
You can also use Polkadot-JS-Apps to interact. These are a collection of tools, utilities and libraries for interacting with the Polkadot network from JavaScript. All code is made available on Github with a permissive Apache-2.0 license.

Example Calls

API HTTPS endpoint

Go
Curl
1
package main
2
3
import (
4
"fmt"
5
"github.com/centrifuge/go-substrate-rpc-client/client"
6
"github.com/centrifuge/go-substrate-rpc-client/rpc/author"
7
"github.com/centrifuge/go-substrate-rpc-client/rpc/chain"
8
"github.com/centrifuge/go-substrate-rpc-client/rpc/state"
9
"github.com/centrifuge/go-substrate-rpc-client/rpc/system"
10
)
11
12
13
func main() {
14
const url_auth = "https://username:[email protected]/xxxxx/xxxxx/kusama/full/main" // authentication
15
const url_token = "https://apis.ankr.com/xxxxx/xxxxx/kusama/full/main" // token
16
17
cl,err := client.Connect("choose url_auth or url_token by your created type")
18
19
if err != nil {
20
panic(err)
21
}
22
23
newRPC, err := NewRPC(cl)
24
if err != nil {
25
panic(err)
26
}
27
28
hash, err := newRPC.Chain.GetFinalizedHead()
29
if err != nil {
30
panic(err)
31
}
32
33
fmt.Println(hash.Hex())
34
35
}
36
37
type RPC struct {
38
Author *author.Author
39
Chain *chain.Chain
40
State *state.State
41
System *system.System
42
Client *client.Client
43
}
44
45
func NewRPC(cl client.Client) (*RPC, error) {
46
st := state.NewState(cl)
47
return &RPC{
48
Author: author.NewAuthor(cl),
49
Chain: chain.NewChain(cl),
50
State: st,
51
System: system.NewSystem(cl),
52
client: cl,
53
}, nil
54
}
Copied!
1
# authentication
2
$ curl -H "Content-Type: application/json" -u "username:password" -d '{"jsonrpc":"2.0","method":"chain_getBlock","params":[],"id":1}' https://apis.ankr.com/xxxxx/xxxxx/kusama/full/main
3
$ curl -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"chain_getBlock","params":[],"id":1}' https://username:[email protected]/xxxxx/xxxxx/kusama/full/main
4
5
# token
6
$ curl -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"chain_getBlock","params":[],"id":1}' https://apis.ankr.com/xxxxx/xxxxx/kusama/full/main
Copied!

Websocket endpoint

Go
JavaScript
Curl
1
package main
2
3
import (
4
"fmt"
5
"github.com/centrifuge/go-substrate-rpc-client/client"
6
"github.com/centrifuge/go-substrate-rpc-client/rpc/author"
7
"github.com/centrifuge/go-substrate-rpc-client/rpc/chain"
8
"github.com/centrifuge/go-substrate-rpc-client/rpc/state"
9
"github.com/centrifuge/go-substrate-rpc-client/rpc/system"
10
"time"
11
)
12
13
14
func main() {
15
const url_auth = "wss://username:[email protected]/wss/xxxxx/xxxxx/kusama/full/main" // authentication
16
const url_token = "wss://apis.ankr.com/wss/xxxxx/xxxxx/kusama/full/main" // token
17
18
cl,err := client.Connect("choose url_auth or url_token by your created type")
19
20
if err != nil {
21
panic(err)
22
}
23
24
newRPC, err := NewWebsocket(cl)
25
if err != nil {
26
panic(err)
27
}
28
29
sub, err := newRPC.Chain.SubscribeNewHeads()
30
if err != nil {
31
panic(err)
32
}
33
34
fmt.Println("---subscribe-----")
35
36
go func() {
37
time.Sleep(10 * time.Second)
38
fmt.Println("---unsubscribe-----")
39
sub.Unsubscribe()
40
}()
41
42
go func() {
43
for c := range sub.Chan {
44
fmt.Println(c.Number)
45
}
46
}()
47
48
<-sub.Err()
49
50
}
51
52
type Websocket struct {
53
Author *author.Author
54
Chain *chain.Chain
55
State *state.State
56
System *system.System
57
Client *client.Client
58
}
59
60
func NewWebsocket(cl client.Client) (*Websocket, error) {
61
st := state.NewState(cl)
62
return &Websocket{
63
Author: author.NewAuthor(cl),
64
Chain: chain.NewChain(cl),
65
State: st,
66
System: system.NewSystem(cl),
67
client: cl,
68
}, nil
69
}
Copied!
1
const { ApiPromise, WsProvider } = require('@polkadot/api');
2
3
async function main() {
4
5
const url_auth = 'wss://username:[email protected]/wss/xxxxx/xxxxx/kusama/full/main' // authentication
6
const url_token = 'wss://[email protected]/wss/xxxxx/xxxxx/kusama/full/main' // token
7
8
const api = await ApiPromise.create({ 'choose url_auth or url_token by your created type' });
9
const lastHdr = await api.rpc.chain.getHeader();
10
11
console.log(`The blockNumber is ${lastHdr.number}`);
12
}
13
14
main().catch(console.error).finally(() => process.exit());
Copied!
1
# authentication
2
$ wscat -c wss://username:[email protected]/wss/xxxxx/xxxxx/kusama/full/main
3
4
# token
5
$ wscat -c wss://apis.ankr.com/wss/xxxxx/xxxxx/kusama/full/main
6
7
wait connected...
8
9
# subscribe
10
> {"jsonrpc":"2.0","method":"chain_subscribeNewHeads","params":[],"id":1}
11
12
# unsubscribe
13
> {"jsonrpc":"2.0","method":"chain_unsubscribeNewHeads","params":["0xxxxxxxxxxxxxxx"],"id":1}
Copied!

Explorers

Kusama Explorer https://polkascan.io/kusama
Last modified 6d ago