Skip to content

Commit 97bb067

Browse files
feat: add omnilock administrator mode example
1 parent b2e9f66 commit 97bb067

File tree

9 files changed

+3911
-10
lines changed

9 files changed

+3911
-10
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules/
2+
index.js
+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Lumos & Omnilock Administrator mode
2+
3+
Nervos maintains a powerful lock
4+
called [Omni Lock](https://github.com/XuJiandong/docs-bank/blob/master/omni_lock.md) (previously named RC lock), which
5+
can use private key as a signer. This example will show how to use Lumos to send a transaction using Omni lock Administrator mode
6+
7+
## Quick Start
8+
9+
```
10+
$ yarn
11+
$ yarn build
12+
```
13+
14+
use lib
15+
```
16+
$ node --experimental-repl-await
17+
18+
# import lib
19+
node> omni = require("./index")
20+
21+
# generate white list sparse merkle tree root & proof
22+
node> { root, proof } = omni.generateWLRule([omni.alice.lockScript.args])
23+
24+
# deploy white list cell with typeId
25+
node> rceCellScript = await omni.deployRCE({ from: omni.alice.address, fromPrivKey: omni.alice.privKey, root })
26+
27+
# generate bob's omnilock administrator addr
28+
node> bobOmniAddr = omni.generateOmniLockAdministratorAddress(omni.bob.lockScript.args.substring(2), rceCellScript.CODE_HASH.substring(2))
29+
30+
# get test CKB from https://faucet.nervos.org/
31+
32+
# wait a moment, and we can find bob's omnilock administrator addr has test CKB
33+
34+
# unlock by administrator (alice) pubkey hash
35+
node> txSkeleton = await omni.buildTransferByOmnilockAdministrator({
36+
rceCellConfig: rceCellScript,
37+
from: bobOmniAddr,
38+
to: omni.alice.address,
39+
amount: "10000000000",
40+
});
41+
42+
node> signedTx = omni.sealOmnilockTxSkeleton(txSkeleton, omni.alice.privKey, omni.alice.lockScript.args, proof);
43+
44+
node> txHash = await omni.rpc.send_transaction(signedTx, "passthrough");
45+
```

0 commit comments

Comments
 (0)