diff --git a/.changeset/large-points-obey.md b/.changeset/large-points-obey.md new file mode 100644 index 00000000..34ad023f --- /dev/null +++ b/.changeset/large-points-obey.md @@ -0,0 +1,7 @@ +--- +"@ckb-ccc/spore": minor +"@ckb-ccc/shell": minor +"@ckb-ccc/ccc": minor +--- + +feat: export backend packages in @ckb-ccc/shell diff --git a/.changeset/swift-stingrays-remain.md b/.changeset/swift-stingrays-remain.md new file mode 100644 index 00000000..eaf41e8e --- /dev/null +++ b/.changeset/swift-stingrays-remain.md @@ -0,0 +1,7 @@ +--- +"@ckb-ccc/core": minor +"@ckb-ccc/ssri": minor +"@ckb-ccc/udt": minor +--- + +feat: SSRI & UDT SDK diff --git a/README.md b/README.md index 84b7afe3..e209b7e4 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ For non-developers, you can [try CCC's app now here](https://app.ckbccc.com/) ([ - [Sign and verify any message.]() ([Playground](https://live.ckbccc.com/?src=https://raw.githubusercontent.com/ckb-devrel/ccc/refs/heads/master/packages/examples/src/sign.ts)) - [Transfer native CKB token.]() ([Playground](https://live.ckbccc.com/?src=https://raw.githubusercontent.com/ckb-devrel/ccc/refs/heads/master/packages/examples/src/transfer.ts)) -- [Transfer xUDT token.]() ([Playground](https://live.ckbccc.com/?src=https://raw.githubusercontent.com/ckb-devrel/ccc/refs/heads/master/packages/examples/src/transferUdt.ts)) +- [Transfer UDT token.]() ([Playground](https://live.ckbccc.com/?src=https://raw.githubusercontent.com/ckb-devrel/ccc/refs/heads/master/packages/examples/src/transferUdt.ts)) - See [Misc: Single-Use-Seals](https://talk.nervos.org/t/en-cn-misc-single-use-seals/8279) to learn how token issuing works in the cell model. - [Issue xUDT token with the Single-Use Lock.]() - [Issue xUDT token controlled by a Type ID cell.]() @@ -131,7 +131,7 @@ Follow the prompts to select your preferred framework template and start buildin We design CCC for both front-end and back-end developers. You need only one package to fulfil all your needs: -- [NodeJS](https://www.npmjs.com/package/@ckb-ccc/core): `npm install @ckb-ccc/core` +- [NodeJS](https://www.npmjs.com/package/@ckb-ccc/shell): `npm install @ckb-ccc/shell` - [Custom UI](https://www.npmjs.com/package/@ckb-ccc/ccc): `npm install @ckb-ccc/ccc` - [Web Component](https://www.npmjs.com/package/@ckb-ccc/connector): `npm install @ckb-ccc/connector` - [React](https://www.npmjs.com/package/@ckb-ccc/connector-react) ([Docs](https://docs.ckbccc.com/modules/_ckb_ccc_connector_react.html)): `npm install @ckb-ccc/connector-react` diff --git a/packages/ccc/package.json b/packages/ccc/package.json index bf27f49f..41cdef12 100644 --- a/packages/ccc/package.json +++ b/packages/ccc/package.json @@ -56,7 +56,7 @@ "access": "public" }, "dependencies": { - "@ckb-ccc/core": "workspace:*", + "@ckb-ccc/shell": "workspace:*", "@ckb-ccc/eip6963": "workspace:*", "@ckb-ccc/joy-id": "workspace:*", "@ckb-ccc/nip07": "workspace:*", diff --git a/packages/ccc/src/advancedBarrel.ts b/packages/ccc/src/advancedBarrel.ts index e971a818..cc735949 100644 --- a/packages/ccc/src/advancedBarrel.ts +++ b/packages/ccc/src/advancedBarrel.ts @@ -1,7 +1,7 @@ -export * from "@ckb-ccc/core/advancedBarrel"; export * from "@ckb-ccc/eip6963/advanced"; export * from "@ckb-ccc/nip07/advanced"; export * from "@ckb-ccc/okx/advanced"; +export * from "@ckb-ccc/shell/advancedBarrel"; export * from "@ckb-ccc/uni-sat/advanced"; export * from "@ckb-ccc/utxo-global/advanced"; export * from "@ckb-ccc/xverse/advanced"; diff --git a/packages/ccc/src/barrel.ts b/packages/ccc/src/barrel.ts index 9720265f..8b46c112 100644 --- a/packages/ccc/src/barrel.ts +++ b/packages/ccc/src/barrel.ts @@ -1,9 +1,9 @@ -export * from "@ckb-ccc/core/barrel"; export * from "@ckb-ccc/eip6963"; export * from "@ckb-ccc/joy-id"; export * from "@ckb-ccc/nip07"; export * from "@ckb-ccc/okx"; export * from "@ckb-ccc/rei"; +export * from "@ckb-ccc/shell/barrel"; export * from "@ckb-ccc/uni-sat"; export * from "@ckb-ccc/utxo-global"; export * from "@ckb-ccc/xverse"; diff --git a/packages/ccc/src/signersController.ts b/packages/ccc/src/signersController.ts index 55171e33..05e58dea 100644 --- a/packages/ccc/src/signersController.ts +++ b/packages/ccc/src/signersController.ts @@ -1,9 +1,9 @@ -import { ccc } from "@ckb-ccc/core"; import { Eip6963 } from "@ckb-ccc/eip6963"; import { JoyId } from "@ckb-ccc/joy-id"; import { Nip07 } from "@ckb-ccc/nip07"; import { Okx } from "@ckb-ccc/okx"; import { Rei } from "@ckb-ccc/rei"; +import { ccc } from "@ckb-ccc/shell"; import { UniSat } from "@ckb-ccc/uni-sat"; import { UtxoGlobal } from "@ckb-ccc/utxo-global"; import { Xverse } from "@ckb-ccc/xverse"; diff --git a/packages/core/src/ckb/transaction.ts b/packages/core/src/ckb/transaction.ts index 68f2c13c..9926382a 100644 --- a/packages/core/src/ckb/transaction.ts +++ b/packages/core/src/ckb/transaction.ts @@ -1487,8 +1487,13 @@ export class Transaction extends mol.Entity.Base< return addedCount; } - async completeInputsByUdt(from: Signer, type: ScriptLike): Promise { - const exceptedBalance = this.getOutputsUdtBalance(type); + async completeInputsByUdt( + from: Signer, + type: ScriptLike, + balanceTweak?: NumLike, + ): Promise { + const exceptedBalance = + this.getOutputsUdtBalance(type) + numFrom(balanceTweak ?? 0); const inputsBalance = await this.getInputsUdtBalance(from.client, type); if (inputsBalance >= exceptedBalance) { return 0; diff --git a/packages/core/src/jsonRpc/requestor.ts b/packages/core/src/jsonRpc/requestor.ts index af7a2c37..bb12785e 100644 --- a/packages/core/src/jsonRpc/requestor.ts +++ b/packages/core/src/jsonRpc/requestor.ts @@ -102,7 +102,10 @@ export class RequestorJsonRpc { outTransformer, ); } catch (err: unknown) { - await this.onError?.(err); + if (!this.onError) { + throw err; + } + await this.onError(err); } } diff --git a/packages/demo/package.json b/packages/demo/package.json index ed50074f..6afbc559 100644 --- a/packages/demo/package.json +++ b/packages/demo/package.json @@ -24,6 +24,7 @@ "devDependencies": { "@ckb-ccc/connector-react": "workspace:*", "@ckb-ccc/lumos-patches": "workspace:*", + "@ckb-ccc/udt": "workspace:*", "@ckb-lumos/ckb-indexer": "^0.24.0-next.1", "@ckb-lumos/common-scripts": "^0.24.0-next.1", "@ckb-lumos/config-manager": "^0.24.0-next.1", diff --git a/packages/demo/src/app/connected/(tools)/TransferUdt/page.tsx b/packages/demo/src/app/connected/(tools)/TransferUdt/page.tsx new file mode 100644 index 00000000..69c052af --- /dev/null +++ b/packages/demo/src/app/connected/(tools)/TransferUdt/page.tsx @@ -0,0 +1,121 @@ +"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"; + +export default function TransferUdt() { + const { client } = ccc.useCcc(); + const { signer, createSender } = useApp(); + const { log } = createSender("Transfer xUDT"); + + const { explorerTransaction } = useGetExplorerLink(); + + const [udtTxHash, setUdtTxHash] = useState(""); + const [udtIndex, setUdtIndex] = useState(""); + const [udtCodeHash, setUdtCodeHash] = useState(""); + const [udtHashType, setUdtHashType] = useState(""); + const [udtArgs, setUdtArgs] = useState(""); + const [transferTo, setTransferTo] = useState(""); + const [amount, setAmount] = useState(""); + + 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 ( +
+