-
Notifications
You must be signed in to change notification settings - Fork 0
/
issuer.js
75 lines (67 loc) · 1.97 KB
/
issuer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { Aggregator, FEE, generateIssuerInfoTx } from "@nervina-labs/cota-sdk";
import { Collector } from "@nervina-labs/cota-sdk";
import pkg, {
rawTransactionToHash,
scriptToHash,
serializeWitnessArgs,
} from "@nervosnetwork/ckb-sdk-utils";
const { addressToScript } = pkg;
const TEST_PRIVATE_KEY =
"0x59df3d4584579a4b8ae77e4d7a851d68178a0e19dbbdd53b5daab543943e1b31";
const TEST_ADDRESS = "ckt1qyqp8ydxwz3p4vcmjwc2d7zqk4xhv707j80q4yrap2";
const secp256k1CellDep = (isMainnet) => {
if (isMainnet) {
return {
outPoint: {
txHash:
"0x71a7ba8fc96349fea0ed3a5c47992e3b4084b031a42264a018e0072e8172e46c",
index: "0x0",
},
depType: "depGroup",
};
}
return {
outPoint: {
txHash:
"0xf8de3bb47d055cdf460d93a2a6e1b05f7432f9777c8c474abf4eec1d4aee5d37",
index: "0x0",
},
depType: "depGroup",
};
};
const run = async () => {
// True for mainnet and false for testnet
const isMainnet = false;
const service = {
collector: new Collector({
ckbNodeUrl: "https://testnet.ckbapp.dev/rpc",
ckbIndexerUrl: "https://testnet.ckbapp.dev/rpc",
}),
aggregator: new Aggregator({
registryUrl: "https://cota.nervina.dev/registry-aggregator",
cotaUrl: "https://cota.nervina.dev/aggregator",
}),
};
const ckb = service.collector.getCkb();
const cotaLock = addressToScript(TEST_ADDRESS);
const issuer = {
name: "Nervos Labs example",
description: "Melting Two Wor.",
avatar: "https://i.loli.net/2021/04/29/IigbpOWP8fw9qDn.png",
};
let rawTx = await generateIssuerInfoTx(
service,
cotaLock,
issuer,
FEE,
isMainnet
);
rawTx.cellDeps.push(secp256k1CellDep(isMainnet));
const signedTx = ckb.signTransaction(TEST_PRIVATE_KEY)(rawTx);
console.log(JSON.stringify(signedTx));
let txHash = await ckb.rpc.sendTransaction(signedTx, "passthrough");
console.info(
`Set issuer information tx has been sent with tx hash ${txHash}`
);
};
run();