https://github.com/polymeshassociation/sub-script
Scripting interface for substrate nodes.
https://github.com/polymeshassociation/sub-script
Last synced: 4 months ago
JSON representation
Scripting interface for substrate nodes.
- Host: GitHub
- URL: https://github.com/polymeshassociation/sub-script
- Owner: PolymeshAssociation
- License: apache-2.0
- Created: 2021-11-15T11:03:28.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2025-04-23T11:52:25.000Z (about 1 year ago)
- Last Synced: 2025-07-25T14:42:51.186Z (11 months ago)
- Language: Rust
- Size: 785 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Sub-script
A simple scripting interface for [Substrate](https://substrate.dev) nodes.
It uses [Rhai](https://rhai.rs) for the scripting engine.
## Features
- Auto generate key pairs for named users by accessing `USER.`.
- Loads chain metadata for all modules, extrinsics, events, storages and types (for v14+ Metadata chains).
- Easy to sign and submit extrinsic calls.
- Spawning sub-task (threads) for load testing.
## Goals
- Flexible - Load chain metadata from node and all custom types from `schema.json` file. No recompile needed.
- Mocking - Easy to share scripts for mocking large number of users, assets, etc.. on a local node for testing UIs.
- Debuging - Provides a low-level interface to the node. Easy to change schema types for testing encoding issues.
## Non-Goals
- This doesn't replace SDKs for other languages. The available libraries will be very limited.
- Please don't use on Mainnet.
## Todo
- Subscribe to storage updates.
- Add REPL support for quickly making extrinsic calls.
## Examples
```rhai
// Use Alice for mocking cdd.
let alice = USER.Alice;
// Generate a test user. Key generated from "//Test123" seed.
let user = USER.Test123;
// Mock Cdd for user and make sure they have some POLYX.
let res = alice.submit(TestUtils.mock_cdd_register_did(user));
if res.is_success {
// New account send them some POLYX.
alice.submit(Balances.transfer(user, 5.0));
}
// Generate another test user. Key generated from "//Key1" seed.
let key = USER.Key1; // Don't mock cdd for this user.
// Add JoinIdentity authorization for `key` to join `user`.
let res = user.submit(Identity.add_authorization(#{
Account: key
}, #{
JoinIdentity: #{
asset: #{ These: ["ACME"] },
extrinsic: #{ Whole: () },
portfolio: #{ Whole: () },
}
}, ()));
if res.is_success {
// call successful.
} else {
// call failed.
print(`failed: ${res.result}`);
}
// Process all events emitted by the call.
for event in res.events {
print(`EventName: ${event.name}`);
print(` Args: ${event.args}`);
}
// Process events matching prefix 'Identity.Auth'.
for event in res.events("Identity.Auth") {
print(`EventName: ${event.name}`);
print(` Args: ${event.args}`);
}
```
See other examples scripts in `./scripts/` folder.