Prerequisites
- A connected signer from
useSigner()or a manualsigner.connect()call. - The
@ckb-ccc/connector-react(React) or@ckb-ccc/ccc(Node.js/scripts) package installed.
Transfer a fixed amount
1
Get the signer
Retrieve the active signer. In a React app use the
useSigner() hook; in a script use a signer instance directly.2
Resolve the destination address
Convert a bech32 CKB address string to a
lock script using ccc.Address.fromString(). Pass the signer’s client so the method can look up the correct address format for the current network.3
Build the transaction
Create a transaction that declares the outputs you want. Specify the amount in Shannon (1 CKB = 10⁸ Shannon). Use
ccc.fixedPointFrom() to convert from a human-readable CKB value.Capacity is the amount of on-chain storage (and CKB) locked in the cell. For a plain CKB transfer the minimum capacity is 61 CKB (the byte size of the cell’s structure).
4
Fill inputs automatically
Call
tx.completeInputsByCapacity(signer) to have CCC scan the signer’s cells and add enough inputs to cover the requested output capacity.5
Calculate and pay the fee
Call
tx.completeFeeBy(signer) to calculate the network fee, add a change output back to the signer if needed, and finalize the transaction.6
Sign and broadcast
Send the transaction.
signer.sendTransaction() signs the transaction and submits it to the network, returning the transaction hash.Full example
transfer.ts
Transfer all CKB
UsecompleteInputsAll() to sweep all cells into a single output, then completeFeeChangeToOutput() to deduct the fee from that output instead of adding a separate change cell.
transfer-all.ts
In a React component
send-button.tsx
Next steps
UDT Tokens
Transfer CKB-native fungible tokens with the UDT package.
Sign Message
Sign an arbitrary message with the connected wallet.