A simple scripting interface for Substrate nodes. It uses Rhai for the scripting engine.
USER.<UserName>
.schema.json
file. No recompile needed.```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.mockcddregisterdid(user)); if res.issuccess { // 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.addauthorization(#{
Account: key
}, #{
JoinIdentity: #{
asset: #{ These: ["ACME"] },
extrinsic: #{ Whole: () },
portfolio: #{ Whole: () },
}
}, ()));
if res.issuccess {
// 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.