@@ -221,23 +221,91 @@ if keypair.verify("Test123", signature):
221
221
By default a keypair is using SR25519 cryptography, alternatively ED25519 can be explictly specified:
222
222
223
223
``` python
224
- keypair = Keypair.create_from_mnemonic(mnemonic, crypto_type = Keypair .ED25519 )
224
+ keypair = Keypair.create_from_mnemonic(mnemonic, crypto_type = KeypairType .ED25519 )
225
225
```
226
226
227
- ### Create keypair using Subkey wrapper (using local subkey binary)
227
+ ### Creating keypairs with soft and hard key derivation paths
228
228
229
229
``` python
230
- sub_key = Subkey(subkey_path = ' /usr/local/bin/subkey' )
231
- subkey_result = sub_key.inspect(network = ' kusama' , suri = " appear fortune produce assist volcano deal shoulder foot engine harvest pupil agent//Alice" )
232
- keypair = Keypair.create_from_seed(subkey_result[" secretSeed" ], address_type = 2 )
230
+ mnemonic = Keypair.generate_mnemonic()
231
+ keypair = Keypair.create_from_uri(mnemonic + ' //hard/soft' )
232
+ ```
233
+
234
+ By omitting the mnemonic the default development mnemonic is used:
235
+
236
+ ``` python
237
+ keypair = Keypair.create_from_uri(' //Alice' )
238
+ ```
239
+
240
+ ### Getting estimate of network fees for extrinsic in advance
241
+
242
+ ``` python
243
+ keypair = Keypair(ss58_address = " EaG2CRhJWPb7qmdcJvy3LiWdh26Jreu9Dx6R1rXxPmYXoDk" )
244
+
245
+ call = self .kusama_substrate.compose_call(
246
+ call_module = ' Balances' ,
247
+ call_function = ' transfer' ,
248
+ call_params = {
249
+ ' dest' : ' EaG2CRhJWPb7qmdcJvy3LiWdh26Jreu9Dx6R1rXxPmYXoDk' ,
250
+ ' value' : 2 * 10 ** 3
251
+ }
252
+ )
253
+ payment_info = self .kusama_substrate.get_payment_info(call = call, keypair = keypair)
254
+ ```
255
+
256
+ ### Offline signing of extrinsics
257
+
258
+ This example generates a signature payload which can be signed on another (offline) machine and later on sent to the
259
+ network with the generated signature.
260
+
261
+ Generate signature payload on online machine:
262
+ ``` python
263
+ substrate = SubstrateInterface(
264
+ url = " http://127.0.0.1:9933" ,
265
+ address_type = 42 ,
266
+ type_registry_preset = ' substrate-node-template' ,
267
+ )
268
+
269
+ call = substrate.compose_call(
270
+ call_module = ' Balances' ,
271
+ call_function = ' transfer' ,
272
+ call_params = {
273
+ ' dest' : ' 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY' ,
274
+ ' value' : 2 * 10 ** 8
275
+ }
276
+ )
277
+
278
+ era = {' period' : 64 , ' current' : 22719 }
279
+ nonce = 0
280
+
281
+ signature_payload = substrate.generate_signature_payload(call = call, era = era, nonce = nonce)
282
+ ```
283
+
284
+ Then on another (offline) machine generate the signature with given ` signature_payload ` :
285
+
286
+ ``` python
287
+ keypair = Keypair.create_from_mnemonic(" nature exchange gasp toy result bacon coin broccoli rule oyster believe lyrics" )
288
+ signature = keypair.sign(signature_payload)
233
289
```
234
290
235
- ### Create keypair using Subkey wrapper (using Docker image parity/subkey : latest )
291
+ Finally on the online machine send the extrinsic with generated signature:
236
292
237
293
``` python
238
- sub_key = Subkey(use_docker = True )
239
- subkey_result = sub_key.inspect(network = ' kusama' , suri = " appear fortune produce assist volcano deal shoulder foot engine harvest pupil agent//Alice" )
240
- keypair = Keypair.create_from_seed(subkey_result[" secretSeed" ], address_type = 2 )
294
+ keypair = Keypair(ss58_address = " 5EChUec3ZQhUvY1g52ZbfBVkqjUY9Kcr6mcEvQMbmd38shQL" )
295
+
296
+ extrinsic = substrate.create_signed_extrinsic(
297
+ call = call,
298
+ keypair = keypair,
299
+ era = era,
300
+ nonce = nonce,
301
+ signature = signature
302
+ )
303
+
304
+ result = substrate.submit_extrinsic(
305
+ extrinsic = extrinsic
306
+ )
307
+
308
+ print (result[' extrinsic_hash' ])
241
309
```
242
310
243
311
### Metadata and type versioning
0 commit comments