CCIP-REACT-COMPONENTS
The CCIP-REACT-COMPONENTS package is a set of prebuilt ready-to-use UI components built on top of CCIP-JS. Using both packages, you can add a fully featured CCIP bridge to your app that can be styled to match your app design.
Table of contents
Installation
Install @chainlink/ccip-react-components:
Using NPM:
npm install @chainlink/ccip-react-components
Using Yarn:
yarn add @chainlink/ccip-react-components
Using PNPM:
pnpm add @chainlink/ccip-react-components
Example Usage
For a working example of how to store, manage and use the NetworkConfig parameters, please refer to the example app here: in the NextJS Example
import 'ccip-react-components/dist/style.css';
import { CCIPWidget, Config, NetworkConfig } from 'ccip-react-components';
import { sepolia, optimismSepolia } from 'viem/chains';
const networkConfing: NetworkConfig = {
chains: [{ chain: sepolia }, { chain: optimismSepolia }],
linkContracts: {
[sepolia.id]: '0x779877A7B0D9E8603169DdbD7836e478b4624789',
[optimismSepolia.id]: '0xE4aB69C077896252FAFBD49EFD26B5D171A32410',
},
routerAddresses: {
[sepolia.id]: '0x0BF3dE8c5D3e8A2B34D2BEeB17ABfCeBaf363A59',
[optimismSepolia.id]: '0x114a20a10b43d4115e5aeef7345a1a71d2a60c57',
},
chainSelectors: {
[sepolia.id]: '16015286601757825753',
[optimismSepolia.id]: '5224473277236331295',
},
tokensList: [
{
symbol: 'CCIP-BnM',
address: {
[sepolia.id]: '0xFd57b4ddBf88a4e07fF4e34C487b99af2Fe82a05',
[optimismSepolia.id]: '0x8aF4204e30565DF93352fE8E1De78925F6664dA7',
},
logoURL:
'https://smartcontract.imgix.net/tokens/ccip-bnm.webp?auto=compress%2Cformat',
},
],
};
const config: Config = {
theme: {
pallette: {
background: '#FFFFFF',
border: '#B3B7C0',
text: '#000000',
}
shape: {
radius: 6
},
}
};
<CCIPWidget config={config} networkConfig={networkConfig} />;
Network config
export type NetworkConfig = {
chains: { chain: Chain; logoURL?: string }[];
tokensList: Token[];
linkContracts: AddressMap;
routerAddresses: AddressMap;
chainSelectors: {
[chainId: number]: string | undefined;
};
};
You should provide configuration for the networks and tokens that your app will support. Refer to CCIP documentation for list of all currently supported chains and tokens. For instructions on acquiring testnet tokens, refer to the documentation on CCIP Test Tokens.
import { CCIPWidget, NetworkConfig } from 'ccip-react-components';
import { sepolia, optimismSepolia } from 'viem/chains';
const networkConfing: NetworkConfig = {
chains: [{ chain: sepolia }, { chain: optimismSepolia }],
linkContracts: {
[sepolia.id]: '0x779877A7B0D9E8603169DdbD7836e478b4624789',
[optimismSepolia.id]: '0xE4aB69C077896252FAFBD49EFD26B5D171A32410',
},
routerAddresses: {
[sepolia.id]: '0x0BF3dE8c5D3e8A2B34D2BEeB17ABfCeBaf363A59',
[optimismSepolia.id]: '0x114a20a10b43d4115e5aeef7345a1a71d2a60c57',
},
chainSelectors: {
[sepolia.id]: '16015286601757825753',
[optimismSepolia.id]: '5224473277236331295',
},
tokensList: [
{
symbol: 'CCIP-BnM',
address: {
[sepolia.id]: '0xFd57b4ddBf88a4e07fF4e34C487b99af2Fe82a05',
[optimismSepolia.id]: '0x8aF4204e30565DF93352fE8E1De78925F6664dA7',
},
logoURL: 'https://smartcontract.imgix.net/tokens/ccip-bnm.webp?auto=compress%2Cformat',
},
],
};
<CCIPWidget networkConfig={networkConfig} />;
Tokens list
tokensList accepts an array of Token objects
export declare type AddressMap = {
[chainId: number]: Address | undefined;
};
export declare type Token = {
symbol: string;
address: AddressMap;
logoURL: string;
tags?: string[];
};
type AddressMap = {
[chainId: number]: Address | undefined;
};
Config
import { CCIPWidget, Config } from 'ccip-react-components';
const config: Config = {
...
};
<CCIPWidget config={config} />;
Chains
allow and deny configuration options are provided to control which chains can be used.
import { mainnet, avalanche } from 'viem/chains';
import { Config } from 'ccip-react-components';
const config: Config = {
chains: { allow: [mainnet.id, avalanche.id] },
};
import { mainnet, avalanche } from 'viem/chains';
import { Config } from 'ccip-react-components';
const config: Config = {
chains: { deny: [mainnet.id, avalanche.id] },
};
You can also specify source chains (chains from which transfers can be sent) and destination chains (chains from which transfers can be received).
import { mainnet, avalanche } from 'viem/chains';
import { Config } from 'ccip-react-components';
const config: Config = {
chains: { from: { allow: [mainnet.id, avalanche.id] } },
};
import { mainnet, avalanche } from 'viem/chains';
import { Config } from 'ccip-react-components';
const config: Config = {
chains: { from: { deny: [mainnet.id, avalanche.id] } },
};
import { mainnet, avalanche } from 'viem/chains';
import { Config } from 'ccip-react-components';
const config: Config = {
chains: { to: { allow: [mainnet.id, avalanche.id] } },
};
import { mainnet, avalanche } from 'viem/chains';
import { Config } from 'ccip-react-components';
const config: Config = {
chains: { to: { deny: [mainnet.id, avalanche.id] } },
};
Preselected chains
You can configure default chains: as soon as the component loads, the chains will display as preselected.
Preselect a chain to send a transfer from:
import { mainnet } from 'viem/chains';
import { Config } from 'ccip-react-components';
const config: Config = { fromChain: mainnet.id };
Preselect a chain to receive a transfer:
import { mainnet } from 'viem/chains';
import { Config } from 'ccip-react-components';
const config: Config = { toChain: mainnet.id };
Preselect Token
You can also specify a default token to display as preselected:
import { Config } from 'ccip-react-components';
const config: Config = { token: 'USDC' };
Wallets
If needed, you can pass additional wallet configurations:
import { Config } from 'ccip-react-components';
const config: Config = { walletConfig: {
injected?: InjectedParameters;
metamask?: MetaMaskParameters;
walletConnect?: WalletConnectParameters;
coinbaseWallet?: CoinbaseWalletParameters;
} };
Theme
You can customize the component's theme to be in line with your app design.
import { Config } from 'ccip-react-components';
const config: Config = { theme:
{
palette?: {
primary?: string;
background?: string;
border?: string;
text?: string;
muted?: string;
input?: string;
popover?: string;
selected?: string;
warning?: string;
warningBackground?: string;
};
shape?: {
radius?: number;
};
};}
Variants
There are three variants: default, compact and drawer
Drawer
If you chose the drawer variant, you need to create and assign a ref in order to control it:
import { useRef } from 'react';
import { TDrawer, CCIPWidget, Config } from 'ccip-react-components';
export const Page = () = {
const drawerRef = useRef<TDrawer>(null);
const toggleDrawer = () => drawerRef.current?.toggleDrawer();
return (
<div>
<button onClick={toggleDrawer}>Open</button>
<CCIPWidget config={config} ref={drawerRef} />
</div>
);
}
Contributing
Please see the main README.
License
CCIP-React-Components is available under the MIT license.