https://github.com/twhy/omnilock-supply-mode
https://github.com/twhy/omnilock-supply-mode
Last synced: 11 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/twhy/omnilock-supply-mode
- Owner: twhy
- Created: 2024-06-28T04:34:22.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-07-01T03:27:50.000Z (almost 2 years ago)
- Last Synced: 2025-05-30T12:48:41.705Z (about 1 year ago)
- Language: TypeScript
- Size: 50.8 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Omnilock Supply Mode / XUDT with Max Supply
This project demos how to mint XUDT that has max supply in [Nervos Network](https://www.nervos.org/).
It uses the supply mode of [Omnilock](https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0042-omnilock/0042-omnilock.md).
## Install
Use either `npm` or `pnpm` is OK.
```sh
$ pnpm i
$ pnpm i -g ts-node
$ cd src
```
## Run
### 1. Generating New Test Accounts
```sh
$ ts-node generate.ts
```
This will generate three test accounts (tom, bob, may) and write them to `accounts.ts`.
### 2. Claim Testnet CKB
Copy `tom's` address in `accounts.ts` and claim some Testnet CKB.
Faucet: https://faucet.nervos.org/
### 3. Create a Supply Mode Omnilock Cell
You can specify an optional max supply which defaults to 10,000.
```sh
$ ts-node omnilock.ts // default max supply: 10,000
$ ts-node omnilock.ts 666666 // specify max supply: 666666
```
After running `omnilock.ts`, some related data will be written to `omnilock_data.ts`.
### 4. Mint XUDT with Max Supply
You can specify an optional mint amount which defaults to 1,000.
```sh
$ ts-node omnilock_mint.ts // default mint amount: 1,000
$ ts-node omnilock_mint.ts 5000 // specify mint amount: 5,000
```
To keep things simple, all minted XUDT goes to `may's` address.
And `CURRENT_SUPPLY` in `omnilock_data.ts` will be updated after each successful minting.
### 5. View Transactions in Explorer
Every successful transaction will be logged in terminal.
Copy the transaction hash and view it in Testnet Explorer: https://pudge.explorer.nervos.org/ .
## A Full Example
```
$ ts-node generate.ts // generate test accounts
// Go to the faucet page and claim some testnet CKB for tom
$ ts-node omnilock.ts // use default max supply 10,000
$ ts-node omnilock_mint.ts 2000 // mint 2000 XUDT for may
$ ts-node omnilock_mint.ts 6000 // mint another 6000 XUDT for may
$ ts-node omnilock_mint.ts 3000 // Error 90: ERROR_EXCEED_SUPPLY
// 2000 + 6000 + 3000 = 11,000 > 10,000
```
## RFC
https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0042-omnilock/0042-omnilock.md#supply-mode
```
CellDeps:
Omnilock Script Cell
sUDT Script Cell
Inputs:
Cell
Data:
Type:
Lock:
code_hash: Omnilock
args:
<... one of the input cell must have owner lock script as lock, to mint>
Outputs:
Cell
Data:
Type:
Lock:
code_hash: Omnilock
args:
Minted sUDT Cell
Data:
Type:
<...>
Witnesses:
WitnessArgs structure:
Lock:
signature:
omni_identity:
preimage:
<...>
```
## Reference
* [Omnilock RFC](https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0042-omnilock/0042-omnilock.md)
* [Omnilock Script Error Codes](https://github.com/nervosnetwork/ckb-script-error-codes/blob/main/by-type-hash/9b819793a64463aed77c615d6cb226eea5487ccfc0783043a587254cda2b6f26.md)
* [Error Code 90: ERROR_EXCEED_SUPPLY](https://github.com/nervosnetwork/ckb-script-error-codes/blob/main/by-type-hash/9b819793a64463aed77c615d6cb226eea5487ccfc0783043a587254cda2b6f26.md#90)