-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
44 changed files
with
1,657 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"@ckb-ccc/core": patch | ||
"@ckb-ccc/ssri": patch | ||
"@ckb-ccc/udt": patch | ||
--- | ||
|
||
feat: SSRI & UDT SDK |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
packages/demo/src/app/connected/(tools)/TransferUdt/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
"use client"; | ||
|
||
import React, { useEffect, useState } from "react"; | ||
import { TextInput } from "@/src/components/Input"; | ||
import { Button } from "@/src/components/Button"; | ||
import { ccc } from "@ckb-ccc/connector-react"; | ||
import { Textarea } from "@/src/components/Textarea"; | ||
import { useGetExplorerLink } from "@/src/utils"; | ||
import { useApp } from "@/src/context"; | ||
import { ButtonsPanel } from "@/src/components/ButtonsPanel"; | ||
import { Udt } from "@ckb-ccc/udt"; | ||
|
||
export default function TransferUdt() { | ||
const { client } = ccc.useCcc(); | ||
const { signer, createSender } = useApp(); | ||
const { log } = createSender("Transfer xUDT"); | ||
|
||
const { explorerTransaction } = useGetExplorerLink(); | ||
|
||
const [udtTxHash, setUdtTxHash] = useState<string>(""); | ||
const [udtIndex, setUdtIndex] = useState<string>(""); | ||
const [udtCodeHash, setUdtCodeHash] = useState<string>(""); | ||
const [udtHashType, setUdtHashType] = useState<string>(""); | ||
const [udtArgs, setUdtArgs] = useState<string>(""); | ||
const [transferTo, setTransferTo] = useState<string>(""); | ||
const [amount, setAmount] = useState<string>(""); | ||
|
||
useEffect(() => { | ||
(async () => { | ||
const script = await client.getKnownScript(ccc.KnownScript.XUdt); | ||
setUdtCodeHash(script.codeHash); | ||
setUdtHashType(script.hashType); | ||
setUdtTxHash(script.cellDeps[0].cellDep.outPoint.txHash); | ||
setUdtIndex(script.cellDeps[0].cellDep.outPoint.index.toString()); | ||
})(); | ||
}, [client]); | ||
|
||
return ( | ||
<div className="flex w-full flex-col items-stretch"> | ||
<Textarea | ||
label="Address" | ||
placeholder="Addresses to transfer to, separated by lines" | ||
state={[transferTo, setTransferTo]} | ||
/> | ||
<TextInput | ||
label="Amount" | ||
placeholder="Amount to transfer for each" | ||
state={[amount, setAmount]} | ||
/> | ||
<TextInput | ||
label="Args" | ||
placeholder="UDT args to transfer" | ||
state={[udtArgs, setUdtArgs]} | ||
/> | ||
<TextInput | ||
label="Code Hash" | ||
placeholder="UDT args to transfer" | ||
state={[udtCodeHash, setUdtCodeHash]} | ||
/> | ||
<TextInput | ||
label="Hash Type" | ||
placeholder="UDT hash type to transfer" | ||
state={[udtHashType, setUdtHashType]} | ||
/> | ||
<TextInput | ||
label="Script Code Tx Hash" | ||
placeholder="Tx hash of the script code" | ||
state={[udtTxHash, setUdtTxHash]} | ||
/> | ||
<TextInput | ||
label="Script Code index" | ||
placeholder="Index of the script code" | ||
state={[udtIndex, setUdtIndex]} | ||
/> | ||
<ButtonsPanel> | ||
<Button | ||
className="self-center" | ||
onClick={async () => { | ||
if (!signer) { | ||
return; | ||
} | ||
const toAddresses = await Promise.all( | ||
transferTo | ||
.split("\n") | ||
.map((addr) => ccc.Address.fromString(addr, signer.client)), | ||
); | ||
const { script: change } = await signer.getRecommendedAddressObj(); | ||
|
||
const udtType = ccc.Script.from({ | ||
codeHash: udtCodeHash, | ||
hashType: udtHashType, | ||
args: udtArgs, | ||
}); | ||
const udt = new Udt( | ||
{ | ||
txHash: udtTxHash, | ||
index: udtIndex, | ||
}, | ||
{ | ||
codeHash: udtCodeHash, | ||
hashType: udtHashType, | ||
args: udtArgs, | ||
}, | ||
); | ||
|
||
const tx = await udt.transfer( | ||
toAddresses.map(({ script }) => ({ | ||
to: script, | ||
amount: amount, | ||
})), | ||
); | ||
const completedTx = await udt.completeUdtBy(tx, signer); | ||
await completedTx.completeInputsByCapacity(signer); | ||
await completedTx.completeFeeBy(signer); | ||
|
||
console.log(completedTx); | ||
|
||
// Sign and send the transaction | ||
const txHash = await signer.sendTransaction(completedTx); | ||
log("Transaction sent:", explorerTransaction(txHash)); | ||
await signer.client.waitTransaction(txHash); | ||
log("Transaction committed:", explorerTransaction(txHash)); | ||
}} | ||
> | ||
Transfer | ||
</Button> | ||
</ButtonsPanel> | ||
</div> | ||
); | ||
} |
100 changes: 0 additions & 100 deletions
100
packages/demo/src/app/connected/(tools)/TransferXUdt/page.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
node_modules/ | ||
misc/ | ||
|
||
*test.js | ||
*test.ts | ||
*test.d.ts | ||
*test.d.ts.map | ||
*spec.js | ||
*spec.ts | ||
*spec.d.ts | ||
*spec.d.ts.map | ||
|
||
tsconfig.json | ||
tsconfig.*.json | ||
eslint.config.mjs | ||
.prettierrc | ||
.prettierignore | ||
|
||
tsconfig.tsbuildinfo | ||
tsconfig.*.tsbuildinfo | ||
.github/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
node_modules/ | ||
|
||
dist/ | ||
dist.commonjs/ | ||
|
||
.npmignore | ||
.prettierrc | ||
tsconfig.json | ||
eslint.config.mjs | ||
.prettierrc | ||
|
||
tsconfig.tsbuildinfo | ||
.github/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"singleQuote": false, | ||
"trailingComma": "all", | ||
"plugins": ["prettier-plugin-organize-imports"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<p align="center"> | ||
<a href="https://app.ckbccc.com/"> | ||
<img alt="Logo" src="https://raw.githubusercontent.com/ckb-devrel/ccc/master/assets/logoAndText.svg" style="height: 8rem; max-width: 90%; padding: 0.5rem 0;" /> | ||
</a> | ||
</p> | ||
|
||
<h1 align="center" style="font-size: 48px;"> | ||
CCC's Support for SSRI | ||
</h1> | ||
|
||
<p align="center"> | ||
<a href="https://www.npmjs.com/package/@ckb-ccc/ssri"><img | ||
alt="NPM Version" src="https://img.shields.io/npm/v/%40ckb-ccc%2Fssri" | ||
/></a> | ||
<img alt="GitHub commit activity" src="https://img.shields.io/github/commit-activity/m/ckb-devrel/ccc" /> | ||
<img alt="GitHub last commit" src="https://img.shields.io/github/last-commit/ckb-devrel/ccc/master" /> | ||
<img alt="GitHub branch check runs" src="https://img.shields.io/github/check-runs/ckb-devrel/ccc/master" /> | ||
<a href="https://live.ckbccc.com/"><img | ||
alt="Playground" src="https://img.shields.io/website?url=https%3A%2F%2Flive.ckbccc.com%2F&label=Playground" | ||
/></a> | ||
<a href="https://app.ckbccc.com/"><img | ||
alt="App" src="https://img.shields.io/website?url=https%3A%2F%2Fapp.ckbccc.com%2F&label=App" | ||
/></a> | ||
<a href="https://docs.ckbccc.com/"><img | ||
alt="Docs" src="https://img.shields.io/website?url=https%3A%2F%2Fdocs.ckbccc.com%2F&label=Docs" | ||
/></a> | ||
</p> | ||
|
||
<p align="center"> | ||
CCC - CKBers' Codebase is a one-stop solution for your CKB JS/TS ecosystem development. | ||
<br /> | ||
Empower yourself with CCC to discover the unlimited potential of CKB. | ||
<br /> | ||
Interoperate with wallets from different chain ecosystems. | ||
<br /> | ||
Fully enabling CKB's Turing completeness and cryptographic freedom power. | ||
</p> | ||
|
||
### Script-Sourced Rich Information | ||
|
||
Read more about SSRI on <a href="https://talk.nervos.org/t/en-cn-script-sourced-rich-information-script/8256">[EN/CN] Script-Sourced Rich Information - 来源于 Script 的富信息</a>. | ||
|
||
NOTE: This is the base package for interaction with SSRI-Compliant scripts. | ||
|
||
If you are looking for UDT support, please refer directly to <a href="https://www.npmjs.com/package/@ckb-ccc/udt">@ckb-ccc/udt</a> which supports both SSRI-compliant UDT and falling back to xUDT. | ||
|
||
### Related Projects | ||
|
||
- [`ssri-server`](https://github.com/ckb-devrel/ssri-server): Server for calling SSRI methods. | ||
- [`ckb_ssri_sdk`](https://github.com/ckb-devrel/ckb_ssri_sdk): A toolkit to help developers build SSRI-Compliant scripts on CKB with production level example script `pausable-udt` for reference. | ||
|
||
<h3 align="center"> | ||
Read more about CCC on <a href="https://docs.ckbccc.com">our website</a> or <a href="https://github.com/ckb-devrel/ccc">GitHub Repo</a>. | ||
</h3> |
Oops, something went wrong.