@ccbridge-sdk/dapp-sdk
v0.0.13
Published
TypeScript SDK with constants and request helpers used by CC Bridge DApps.
Readme
@ccbridge-sdk/dapp-sdk
TypeScript SDK with constants and request helpers used by CC Bridge DApps.
Installation
yarn add @ccbridge-sdk/dapp-sdk
# or
npm i @ccbridge-sdk/dapp-sdkUsage
import { BRIDGE_CONTRACT_ADDRESS, getAgreement, getEvmHistory } from '@ccbridge-sdk/dapp-sdk';
const agreement = await getAgreement({ party: 'Alice::fingerprint' });
const history = await getEvmHistory({
sender: '0x0000000000000000000000000000000000000000',
rowsPerPage: 10,
pageParam: 0,
});
console.log(BRIDGE_CONTRACT_ADDRESS, agreement, history);Developer notes
Agreement (required)
Before transferring to or from a party, the party must have an active agreement. If the agreement is not created, the bridge flow will fail.
- Check if an agreement exists:
getAgreement({ party }) - Create an agreement:
- The party owner signs the agreement payload using their Ed25519 private key
- Use
prepareAgreementCreateto get a payload to sign - Use
submitAgreementCreateto submit the signed payload
Transfer from Canton
To transfer assets from Canton, you typically:
- Prepare the transfer details (server-side prepare step)
- Have the party owner sign the prepared payload (Ed25519)
- Submit the signed payload (server-side submit step)
This SDK exposes the prepareCantonWithDraw / submitCantonWithDraw helpers for the Console Wallet API part of that flow.
Transfer from EVM
To transfer from EVM, a DApp usually needs an off-chain component (backend/relayer) that:
- Watches EVM events / transaction status
- Builds and submits the corresponding Canton-side communication
To simplify EVM-side integration, this package exports:
BRIDGE_ABI(bridge contract ABI)ERC20_ABI(ERC-20 ABI)BRIDGE_CONTRACT_ADDRESS(default bridge address)
const tx = await activeWallet?.wallet.writeContract({
address: BRIDGE_CONTRACT_ADDRESS,
abi: BRIDGE_ABI,
account: activeWallet.wallet.account,
chain: activeWallet.wallet.chain,
functionName: 'sendCanonicalTokenToCanton',
args: [tokenAddress, amount, textToHex(partyId)],
value: tokenAddress === zeroAddress ? amount : undefined,
});Stealth transfers
Stealth transfers require a Canton Wallet that supports encryption.
- Once stealth data is created/registered, you can transfer to EVM and later decrypt the EVM private key using your Canton Wallet (for the same
party). - If stealth data is re-created (re-registered), you will lose the ability to decrypt EVM keys created before the re-creation.
Requests
All request helpers are exported from @ccbridge/dapp-sdk. Each request supports an optional requestUrlOverride field (when present) to override the base URL used for the call.
| Function | Purpose | Request type | Response type |
| ------------------------ | ------------------------------------------------------------------ | ------------------------------- | -------------------------------- |
| getAgreement | Fetches Canton bridge agreement status by party. | GetAgreementRequest | GetAgreementResponse |
| prepareAgreementCreate | Prepares agreement creation (server-side preparation step). | PrepareAgreementCreateRequest | PrepareAgreementCreateResponse |
| submitAgreementCreate | Submits agreement creation (server-side submit step). | SubmitAgreementCreateRequest | SubmitAgreementCreateResponse |
| prepareCantonWithDraw | Prepares a Canton withdraw via Console Wallet API. | PrepareCantonWithDrawRequest | PrepareCantonWithDrawResponse |
| submitCantonWithDraw | Submits a Canton withdraw via Console Wallet API. | SubmitCantonWithDrawRequest | SubmitCantonWithDrawResponse |
| getStealthAddress | Fetches the registered stealth identity for an address/public key. | GetStealthAddressRequest | GetStealthAddressResponse |
| registerStealthAddress | Registers a stealth identity. | RegisterStealthAddressRequest | RegisterStealthAddressResponse |
| getCantonHistory | Lists Canton transfer statuses. | GetCantonHistoryRequest | GetCantonHistoryResponse |
| getEvmHistory | Returns merged EVM history (send + receive) sorted by createdAt. | GetEvmHistoryRequest | GetEvmHistoryResponse |
| getStealthHistory | Lists EVM bridge jobs (stealth-related history). | GetStealthHistoryRequest | GetStealthHistoryResponse |
Constants
All constants are exported from @ccbridge/dapp-sdk:
| Name | Value | Description |
| ------------------------- | -------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
| CANTON_NETWORK | CANTON_NETWORK | Key/name used by consumers to refer to the Canton network. |
| EVM_CHAIN_ID | 1 | EVM chain id (Ethereum Mainnet). |
| EVM_EXPLORER | https://etherscan.io/ | Default EVM explorer base URL. |
| CC_VIEW | https://ccview.io/ | CC View base URL. |
| BRIDGE_CONTRACT_ADDRESS | 0x287d38Ca1d89Cd3c435A8279Ac9A3528dDeB9131 | EVM Bridge contract address. |
| AGREEMENT_API | https://ccbridge.xyz/ | Default base URL for Canton agreement-related API. |
| EVM_HISTORY_API | https://ccbridge.xyz/ | Default base URL for EVM history API. |
| CANTON_WALLET_API | https://consolewallet.io/ | Default base URL for Console Wallet API. |
| ERC20_ABI | (exported) | ERC-20 ABI definition. |
| BRIDGE_ABI | (exported) | Bridge contract ABI definition. |
| zeroAddress | 0x0000000000000000000000000000000000000000 | EVM zero address constant. |
| EVM_CHAIN_METADATA | (exported) | Token metadata map per EVM network (contract address → name/symbol/decimals/icon). |
| TokenMetadata | (exported) | Type for token metadata entries used in EVM_CHAIN_METADATA. |
| PairId | (exported) | Enum of supported token pair identifiers (e.g. usdc, eth, wbtc). |
| PairInfo | (exported) | Type describing a single token pair (cc + evm token data). |
| PAIRS | (exported) | Helper that returns the supported pair map for given EVM + Canton network variants. NOTE: balances must be fetched by dapp consumer |
