Skip to content

Commit

Permalink
Merge pull request #17 from twhy/xudt-info
Browse files Browse the repository at this point in the history
docs: add docs and code showing how to build xudt info
  • Loading branch information
duanyytop authored Jun 27, 2024
2 parents fd9a048 + de0cd90 commit 05d92cd
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,25 @@ symbol: variable max 255
...

```
**Notice: The xUDT information format is NOT a key-value structure.**

You can find the code about how to construct the xUDT information data in `generator-example/src/lumos.ts`
```ts
const coin = {
decimal: 6,
name: "UNIQUE COIN",
symbol: "UNC",
};

const data = bytes.hexify(bytes.concat(
Uint8.pack(coin.decimal),
Uint8.pack(coin.name.length),
new TextEncoder().encode(coin.name),
Uint8.pack(coin.symbol.length),
new TextEncoder().encode(coin.symbol),
));
```


## Development

Expand Down
23 changes: 17 additions & 6 deletions generator-example/src/lumos.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { hd, utils, config, helpers, commons, RPC, Indexer, HashType, DepType, Input } from '@ckb-lumos/lumos';
import { bytes, blockchain, Uint64 } from '@ckb-lumos/lumos/codec';
import { bytes, blockchain, Uint8, Uint64 } from '@ckb-lumos/lumos/codec';

// For test only, you should NEVER expose your mnemonic or privateKey in production
export const tom = {
Expand Down Expand Up @@ -56,11 +56,22 @@ async function main() {
...UNIQUE_CELL.TESTNET.TYPE_SCRIPT,
args: bytes.hexify(new Uint8Array(20)), // 20 bytes placeholder
};
const cell = helpers.cellHelper.create({
lock,
type,
data: bytes.hexify(new TextEncoder().encode("Unique Cell is Awesome!")) // Relace with XUDT Info
});

const coin = {
decimal: 6,
name: "UNIQUE COIN",
symbol: "UNC",
};

const data = bytes.hexify(bytes.concat(
Uint8.pack(coin.decimal),
Uint8.pack(coin.name.length),
new TextEncoder().encode(coin.name),
Uint8.pack(coin.symbol.length),
new TextEncoder().encode(coin.symbol),
));

const cell = helpers.cellHelper.create({ lock, type, data });

let txSkeleton = helpers.TransactionSkeleton({ cellProvider: indexer });
txSkeleton = helpers.addCellDep(txSkeleton, UNIQUE_CELL.TESTNET.CELL_DEP);
Expand Down

0 comments on commit 05d92cd

Please sign in to comment.