Skip to content

Commit 4355988

Browse files
committed
doc: additional guides and updated README
1 parent 4a46bbd commit 4355988

File tree

2 files changed

+141
-0
lines changed

2 files changed

+141
-0
lines changed

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ We have done everything!
110110
- [Transfer native CKB token.](https://live.ckbccc.com/?src=https://raw.githubusercontent.com/ckb-devrel/ccc/refs/heads/master/packages/examples/src/transfer.ts)
111111
- [Transfer all native CKB token.](https://live.ckbccc.com/?src=https://raw.githubusercontent.com/ckb-devrel/ccc/refs/heads/master/packages/examples/src/transferAll.ts)
112112
- [Transfer UDT token.](https://live.ckbccc.com/?src=https://raw.githubusercontent.com/ckb-devrel/ccc/refs/heads/master/packages/examples/src/transferUdt.ts)
113+
- [Interact with UDT through @ckb-ccc/udt](https://live.ckbccc.com/?src=https://raw.githubusercontent.com/ckb-devrel/ccc/refs/heads/master/packages/examples/src/udt/quickstart.ts):
114+
- [Get UDT symbol through @ckb-ccc/udt.](https://live.ckbccc.com/?src=https://raw.githubusercontent.com/ckb-devrel/ccc/refs/heads/master/packages/examples/src/udt/symbol.ts)
115+
- [Check if a lock hash has been paused through @ckb-ccc/udt.](https://live.ckbccc.com/?src=https://raw.githubusercontent.com/ckb-devrel/ccc/refs/heads/master/packages/examples/src/pausableUdt/isPaused.ts)
116+
- [Transfer UDT token through @ckb-ccc/udt.](https://live.ckbccc.com/?src=https://raw.githubusercontent.com/ckb-devrel/ccc/refs/heads/master/packages/examples/src/udt/transfer.ts)
113117

114118
## Quick Start with `create-ccc-app` (Recommended)
115119

@@ -221,6 +225,12 @@ import { generateDefaultScriptInfos } from "@ckb-ccc/lumos-patches";
221225
registerCustomLockScriptInfos(generateDefaultScriptInfos());
222226
```
223227

228+
## Additional Guides
229+
230+
### SSRI (Script Sourced Rich Information)
231+
232+
- [Quick Starts: Interact with SSRI-Compliant UDT Script with @ckb-ccc/udt](https://github.com/ckb-devrel/ccc/tree/master/guides/quickstart_udt.md)
233+
224234
## Links
225235

226236
- [CCC Playground](https://live.ckbccc.com/) and its [source code](https://github.com/ckb-devrel/ccc/tree/master/packages/playground) help you experiment with CCC instantly in browsers.

guides/quickstart_udt.md

+131
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
# Quick Starts: Interact with SSRI-Compliant UDT Script with @ckb-ccc/udt
2+
3+
> The following guide uses UDT and Pausable UDT as example and assume you're using the playground environment which provides the signer. Your signer would be different based on your project setup.
4+
5+
## Example 1: Prepare and Setup a UDT instance
6+
7+
1. Create or setup your project with CCC (see guide [here](https://docs.ckbccc.com/index.html#md:quick-start-with-create-ccc-app-recommended))
8+
9+
2. Start up your local SSRI server through docker:
10+
11+
```shell
12+
docker run -p 9090:9090 hanssen0/ckb-ssri-server
13+
```
14+
15+
3. Prepare the `OutPoint` of your SSRI-compliant UDT script. It's recommended to deploy your UDT script with Type ID, and the following way would allow you to get the `OutPoint` programmatically even if the script gets upgraded:
16+
17+
```ts
18+
import { ccc } from "@ckb-ccc/ccc";
19+
import { signer } from "@ckb-ccc/playground";
20+
// Note: Your signer would be different based on your project setup.
21+
22+
const pudtScriptCell = await signer.client.findSingletonCellByType({
23+
codeHash:
24+
"0x00000000000000000000000000000000000000000000000000545950455f4944",
25+
hashType: "type",
26+
args: "0xf0bad0541211603bf14946e09ceac920dd7ed4f862f0ffd53d0d477d6e1d0f0b",
27+
});
28+
if (!scriptCell) {
29+
throw new Error("pudt script cell not found");
30+
}
31+
```
32+
33+
4. Prepare the Type script object of your UDT. You can provide the code hash yourself by copying from the explorer, or get it programmatically from the `OutPoint` of your UDT script.
34+
35+
```ts
36+
const pudtCodeHash = pudtScriptCell.cellOutput.type?.hash();
37+
if (!pudtCodeHash) {
38+
throw new Error("PUDT code hash not found");
39+
}
40+
const pudtType = {
41+
codeHash: pudtCodeHash,
42+
hashType: "type",
43+
args: "0x02c93173368ec56f72ec023f63148461b80e7698eddd62cbd9dbe31a13f2b330",
44+
};
45+
```
46+
47+
5. You have everything ready, now you can create an instance of your UDT and interact with it.
48+
49+
```ts
50+
const executor = new ccc.ssri.ExecutorJsonRpc("http://localhost:9090");
51+
const pudt = new ccc.udt.Udt(pudtScriptCell.outPoint, pudtType, {
52+
executor,
53+
});
54+
const pudtName = await pudt.name();
55+
const pudtIcon = await pudt.icon();
56+
console.log(pudtName);
57+
// {"res":"pudt Token","cellDeps":[]}
58+
console.log(pudtIcon);
59+
// {"res":"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNDgiIGhlaWdodD0iNDgiIHZpZXdCb3g9IjAgMCA0OCA0OCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPGNpcmNsZSBjeD0iMjQiIGN5PSIyNCIgcj0iMjQ ......
60+
```
61+
62+
The same script might have implemented multiple SSRI traits or sub-traits at the same time, but you can instantiate the same script arbitrarily with different traits as long as the script implemented the traits you want.
63+
64+
```ts
65+
const pudt = new ccc.udt.UdtPausable(pudtScriptCell.outPoint, pudtType, {
66+
executor,
67+
});
68+
const pudtEnumeratePaused = await pudt.enumeratePaused();
69+
console.log(pudtEnumeratePaused);
70+
// {"res":["0xb5202efa0f2d250af66f0f571e4b8be8b272572663707a052907f8760112fe35","0xa320a09489791af2e5e1fe84927eda84f71afcbd2c7a65cb419464fe46e75085"],"cellDeps":[{"txHash":"0x98c37eabc1672c4a0a30c0bb284ed49308f0cb58b0d8791f44cca168c973e7da","index":"0"}]}
71+
```
72+
73+
## Example 2: Generate and Send a Transaction through @ckb-ccc/udt
74+
75+
1. Some of the methods allows you to generate a transaction object directly while taking care of most of the details for you. You just need to follow the guidance of the docs provided via your IDE.
76+
77+
```ts
78+
const receiverA =
79+
"ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsq2jk6pyw9vlnfakx7vp4t5lxg0lzvvsp3c5adflu";
80+
81+
const { script: lockA } = await ccc.Address.fromString(
82+
receiverA,
83+
signer.client
84+
);
85+
86+
const pudtTransferTx = (
87+
await pudt.transfer(signer, [
88+
{
89+
to: lockA,
90+
amount: 10000,
91+
},
92+
])
93+
).res;
94+
```
95+
96+
Many of these methods also allow you to pass in a previous `ccc.TransactionLike` object as the second argument, which allows you for example to transfer multiple UDT cells in a single transaction.
97+
98+
```ts
99+
const receiverB =
100+
"ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqflz4emgssc6nqj4yv3nfv2sca7g9dzhscgmg28x";
101+
const { script: lockB } = await ccc.Address.fromString(
102+
receiverB,
103+
signer.client
104+
);
105+
let combinedTransferTx = (
106+
await pudt.transfer(
107+
signer,
108+
[
109+
{
110+
to: lockB,
111+
amount: 20000,
112+
},
113+
],
114+
pudtTransferTx
115+
)
116+
).res;
117+
```
118+
119+
2. You only need to complete the inputs of the transaction just like processing any other transactions with CCC.
120+
121+
```ts
122+
// Note: You need to connect your wallet for the following parts. You also need to have enough balance of pudt in your wallet.
123+
combinedTransferTx = await pudt.completeBy(combinedTransferTx, signer);
124+
await combinedTransferTx.completeFeeBy(signer);
125+
await render(combinedTransferTx);
126+
const combinedTransferTxHash = await signer.sendTransaction(combinedTransferTx);
127+
128+
console.log(combinedTransferTxHash);
129+
```
130+
131+
Full runnable example can be found at [here](https://live.ckbccc.com/?src=nostr:nevent1qqs8q20jvxqfsrhqw4te248qduex39dgls7qajhuc42kale0yqatdhspzemhxue69uhhyetvv9ujumn0wd68ytnzv9hxgqg5waehxw309ahx7um5wghx77r5wghxgetkqy28wumn8ghj7un9d3shjtnyv9kh2uewd9hspusjlf)

0 commit comments

Comments
 (0)