Open HRMP Channel
(Original hackmd file here)
Steps to open HRMP channels:
  1. 1.
    Sender parachain send a init open channel request.
  2. 2.
    Recipient parachain accept request.
The steps above are done via Xcm::Transact from the sender's or recipient's part.
Given example of Karura and Statemine bi-direction channel communicate, there're two steps needs to be done on each parachain side:
Karura:
  • hrmpInitOpenChannel(1000) : Initiate open HRMP channel request to Statemine
  • hrmpAcceptOpenChannel(1000) : Accept HRMP channel request from Statemine
Statemine:
  • hrmpInitOpenChannel(2000) : Initiate open HRMP channel request to Karura
  • hrmpAcceptOpenChannel(2000) : Accept HRMP channel request from Karura
If Karura and Statemine just have one single direction channel which only allow Karura to Statemine but not allow Statemine to Karura, then there're only one steps done on each side:
  • Karura: hrmpInitOpenChannel(1000): Initiate open HRMP channel request to Statemine
  • Statemine: hrmpAcceptOpenChannel(2000) : Accept HRMP channel request from Karura
In the example below, we're doing Karura to Statemine single one direction open channel.

Send init open channel request

Generate encoded transact

In PolkadotJS app, switch to the live Polkadot/Kusama network. Go to Developer -> Javascript section. Run the encoding code, note to replace the demo recipient para id 1000 with your recipient:
1
const tx = api.tx.hrmp.hrmpInitOpenChannel(1000, 1000, 102400);
2
console.log(tx.toHex());
Copied!
The result will be like 0x3c043c00e8030000e803000000900100, remove the leading hex 3c04, and the encoded result is 0x3c00e8030000e803000000900100.

Send request

Go to PolkadotJS app, switch to sender parachain(here is Karura). Go to Developer -> Sudo section.
Use ormlXcm -> sendAsSovereign to send the transaction. The xcm message format(v2):
Notice there are two fields should be changed:
  • <relay-chain-encoded-hex-call>: 0x3c00e8030000e803000000900100
  • <parachain-id>: 2000
Note: the parachain-id is your parachain, Karura's parachain id is 2000
1
ormlXcm.sendAsSovereign(
2
dest: XcmVersionedMultiLocation
3
{
4
V1: {
5
parents: 1
6
interior: {
7
X1: {
8
Parachain: <parachain-id>
9
}
10
}
11
}
12
}
13
14
message: XcmVersionedXcm
15
{
16
V2: [
17
{
18
WithdrawAsset: [
19
{
20
id: {
21
Concrete: {
22
parents: 0
23
interior: {
24
X1: {
25
Parachain: <parachain-id>
26
}
27
}
28
}
29
}
30
fun: {
31
Fungible: 1,000,000,000,000
32
}
33
}
34
]
35
}
36
{
37
BuyExecution: {
38
fees: {
39
id: {
40
Concrete: {
41
parents: 0
42
interior: {
43
X1: {
44
Parachain: <parachain-id>
45
}
46
}
47
}
48
}
49
fun: {
50
Fungible: 1,000,000,000,000
51
}
52
}
53
weightLimit: Unlimited
54
}
55
}
56
{
57
Transact: {
58
originType: Native
59
requireWeightAtMost: 5,000,000,000
60
call: {
61
encoded: <relay-chain-encoded-hex-call>
62
}
63
}
64
}
65
{
66
DepositAsset: {
67
assets: {
68
Wild: All
69
}
70
maxAssets: 1
71
beneficiary: {
72
parents: 0
73
interior: {
74
X1: {
75
Parachain: <parachain-id>
76
}
77
}
78
}
79
}
80
}
81
]
82
}
83
)
Copied!
To confirm the request was sent, switch to Polkadot/Kusama, go to Developer -> Chain State, check hrmp -> hrmpOpenChannelRequests.

Accept open channel request

Generate encoded transact

In PolkadotJS app, switch to the live Polkadot/Kusama network. Go to Developer -> Javascript section. Run the encoding code, Karura's parachain id is 2000:
1
const tx = api.tx.hrmp.hrmpAcceptOpenChannel(2000);
2
console.log(tx.toHex());
Copied!
The result will be like 0x1c043c01d0070000, remove the leading hex 1c04, and the encoded result is 0x3c01d0070000.

Send request

Go to PolkadotJS app, switch to recipient parachain. Go to Developer -> Sudo section.
Use ormlXcm -> sendAsSovereign to send the transaction. The xcm message format likes:
Notice there are two fields that should be changed:
  • <relay-chain-encoded-hex-call>: 0x3c01d0070000
  • <parachain-id>: 2000
1
ormlXcm.sendAsSovereign(
2
dest: XcmVersionedMultiLocation
3
{
4
V1: {
5
parents: 1
6
interior: {
7
X1: {
8
Parachain: <parachain-id>
9
}
10
}
11
}
12
}
13
14
message: XcmVersionedXcm
15
{
16
V2: [
17
{
18
WithdrawAsset: [
19
{
20
id: {
21
Concrete: {
22
parents: 0
23
interior: {
24
X1: {
25
Parachain: <parachain-id>
26
}
27
}
28
}
29
}
30
fun: {
31
Fungible: 1,000,000,000,000
32
}
33
}
34
]
35
}
36
{
37
BuyExecution: {
38
fees: {
39
id: {
40
Concrete: {
41
parents: 0
42
interior: {
43
X1: {
44
Parachain: <parachain-id>
45
}
46
}
47
}
48
}
49
fun: {
50
Fungible: 1,000,000,000,000
51
}
52
}
53
weightLimit: Unlimited
54
}
55
}
56
{
57
Transact: {
58
originType: Native
59
requireWeightAtMost: 5,000,000,000
60
call: {
61
encoded: <relay-chain-encoded-hex-call>
62
}
63
}
64
}
65
{
66
DepositAsset: {
67
assets: {
68
Wild: All
69
}
70
maxAssets: 1
71
beneficiary: {
72
parents: 0
73
interior: {
74
X1: {
75
Parachain: <parachain-id>
76
}
77
}
78
}
79
}
80
}
81
]
82
}
83
)
Copied!