Skip to content

Commit 3d58260

Browse files
Updates
1 parent 6529ef5 commit 3d58260

File tree

4 files changed

+101
-40
lines changed

4 files changed

+101
-40
lines changed

public/changelog.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
11
[
2+
{
3+
"category": "release",
4+
"changes": [],
5+
"date": "2024-12-12",
6+
"description": "The [CCIP JavaScript SDK](https://github.com/smartcontractkit/ccip-javascript-sdk) is now available, introducing two packages to simplify management of cross-chain token transfers, and to integrate CCIP with the frontend of your own app.\n\nThe [CCIP JavaScript SDK guide](https://docs.chain.link/ccip/ccip-javascript-sdk) introduces the features of the SDK and shows how to run an example app so you can explore the SDK's capabilities.",
7+
"relatedNetworks": [],
8+
"relatedTokens": [],
9+
"title": "CCIP JavaScript SDK",
10+
"topic": "ccip",
11+
"urls": []
12+
},
213
{
314
"category": "release",
415
"changes": [],
50.7 KB
Loading

src/config/sidebar.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,6 +1001,10 @@ export const SIDEBAR: Partial<Record<Sections, SectionEntry[]>> = {
10011001
{
10021002
section: "Guides",
10031003
contents: [
1004+
{
1005+
title: "Using the CCIP JavaScript SDK",
1006+
url: "ccip/ccip-javascript-sdk",
1007+
},
10041008
{
10051009
title: "Transfer Tokens",
10061010
url: "ccip/tutorials/transfer-tokens-from-contract",

src/content/ccip/ccip-javascript-sdk.mdx

Lines changed: 86 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ date: Last Modified
44
title: "Using the CCIP JavaScript SDK"
55
---
66

7-
import { Aside } from "@components"
8-
import { Tabs, TabsContent } from "@components/Tabs"
7+
import { Aside, ClickToZoom } from "@components"
8+
import { Tabs } from "@components/Tabs"
99

1010
The [CCIP JavaScript SDK](https://github.com/smartcontractkit/ccip-javascript-sdk/tree/main) is a tool that helps you to simplify management of cross-chain token transfers, and to integrate CCIP with the frontend of your own app.
1111

@@ -64,12 +64,23 @@ Failure to escape or sanitize error messages could expose your application to **
6464
```
6565
</Fragment>
6666
</Tabs>
67-
- The `./pnpm-workspace.yaml` file specifies all the packages in this repo, and the install command installs dependencies for each of the listed packages.
6867
- `pnpm dev-example` runs an example NextJS app locally. Navigate to http://localhost:3000 in your browser.
6968

7069
## Run an example app
7170

72-
If you run the example NextJS app (using `pnpm dev-example`), you can interact with an example UI that uses the CCIPWidget.
71+
The example Next.js app included with the CCIP JavaScript SDK demonstrates the SDK's functionalities within an interactive web application, allowing you to see its features in action.
72+
73+
To get started:
74+
75+
1. Launch the app by using the following command:
76+
77+
```sh
78+
pnpm dev-example
79+
```
80+
81+
1. In your browser, navigate to http://localhost:3000/ to see the interactive app:
82+
83+
<ClickToZoom src="/images/ccip/ccip-sdk-example-app-ui.png" alt="CCIP JavaScript SDK example app" />
7384

7485
## Review a basic UI example
7586

@@ -83,7 +94,7 @@ Review the reference documentation:
8394

8495
Review the basic UI example below:
8596

86-
```solidity
97+
```ts
8798
import 'ccip-react-components/dist/style.css';
8899
import { CCIPWidget, Config, Token } from 'ccip-react-components';
89100
import { sepolia, optimismSepolia } from 'viem/chains';
@@ -130,9 +141,47 @@ const config: Config = {
130141
<CCIPWidget config={config} tokensList={tokensList} />;
131142
```
132143

133-
## Run a CCIP-JS example app
144+
### Theme configuration
145+
146+
You can customize the component's theme to be in line with your app design. These are all the options available for theme configuration:
147+
148+
```ts
149+
import { Config } from 'ccip-react-components';
150+
const config: Config = { theme:
151+
{
152+
/** Define the app colors in HEX format */
153+
palette?: {
154+
/** Titles color and primary button background, default #000000 */
155+
primary?: string;
156+
/** Background color, default '#FFFFFF' */
157+
background?: string;
158+
/** Border color, default '#B3B7C0' */
159+
border?: string;
160+
/** Text color, default '#000000' */
161+
text?: string;
162+
/** Secondary text, inactive and placeholders color, default '#6D7480' */
163+
muted?: string;
164+
/** Input fields background color, default '#FFFFFF' */
165+
input?: string;
166+
/** Popovers, dropdowns and select fields background color, default '#F5F7FA' */
167+
popover?: string;
168+
/** Selected field from a dropdown background color, default '#D7DBE0' */
169+
selected?: string;
170+
/** Warning text color, default '#F7B955' */
171+
warning?: string;
172+
/** Warning text background color, default '#FFF5E0' */
173+
warningBackground?: string;
174+
};
175+
shape?: {
176+
/** Border radius size in px default 6 */
177+
radius?: number;
178+
};
179+
};}
180+
```
134181

135-
This example app covers the following steps:
182+
## Review a CCIP-JS example
183+
184+
This example uses the `ccip-js` package and covers the following steps:
136185

137186
- Initialize CCIP-JS Client for mainnet
138187
- Approve tokens for transfer
@@ -145,10 +194,10 @@ Review the [reference documentation](https://github.com/smartcontractkit/ccip-ja
145194

146195
### Review the code
147196

148-
```solidity
149-
import * as CCIP from '@chainlink/ccip-js'
150-
import { createWalletClient, custom } from 'viem'
151-
import { mainnet } from 'viem/chains'
197+
```ts
198+
import * as CCIP from "@chainlink/ccip-js"
199+
import { createWalletClient, custom } from "viem"
200+
import { mainnet } from "viem/chains"
152201

153202
// Initialize CCIP-JS Client for mainnet
154203
const ccipClient = CCIP.createClient()
@@ -164,8 +213,8 @@ const walletClient = createWalletClient({
164213
// Approve Router to transfer tokens on user's behalf
165214
const { txHash, txReceipt } = await ccipClient.approveRouter({
166215
client: walletClient,
167-
routerAddress: '0xabcdefabcdefabcdefabcdefabcdefabcdefabcdef',
168-
tokenAddress: '0xabcdefabcdefabcdefabcdefabcdefabcdefabcdef',
216+
routerAddress: "0xabcdefabcdefabcdefabcdefabcdefabcdefabcdef",
217+
tokenAddress: "0xabcdefabcdefabcdefabcdefabcdefabcdefabcdef",
169218
amount: 1000000000000000000n,
170219
waitForReceipt: true,
171220
})
@@ -175,55 +224,45 @@ console.log(`Transfer approved. Transaction hash: ${txHash}. Transaction receipt
175224
// Get fee for the transfer
176225
const fee = await ccipClient.getFee({
177226
client: publicClient,
178-
routerAddress: '0xabcdefabcdefabcdefabcdefabcdefabcdefabcdef',
179-
tokenAddress: '0xabcdefabcdefabcdefabcdefabcdefabcdefabcdef',
227+
routerAddress: "0xabcdefabcdefabcdefabcdefabcdefabcdefabcdef",
228+
tokenAddress: "0xabcdefabcdefabcdefabcdefabcdefabcdefabcdef",
180229
amount: 1000000000000000000n,
181-
destinationAccount: '0x1234567890abcdef1234567890abcdef12345678',
182-
destinationChainSelector: '1234',
230+
destinationAccount: "0x1234567890abcdef1234567890abcdef12345678",
231+
destinationChainSelector: "1234",
183232
})
184233

185234
console.log(`Fee: ${fee.toLocaleString()}`)
186235

187236
// Variant 1: Transfer via CCIP using native token fee
188237
const { txHash, messageId } = await client.transferTokens({
189238
client: walletClient,
190-
routerAddress: '0xabcdefabcdefabcdefabcdefabcdefabcdefabcdef',
191-
tokenAddress: '0xabcdefabcdefabcdefabcdefabcdefabcdefabcdef',
239+
routerAddress: "0xabcdefabcdefabcdefabcdefabcdefabcdefabcdef",
240+
tokenAddress: "0xabcdefabcdefabcdefabcdefabcdefabcdefabcdef",
192241
amount: 1000000000000000000n,
193-
destinationAccount: '0x1234567890abcdef1234567890abcdef12345678',
194-
destinationChainSelector: '1234',
242+
destinationAccount: "0x1234567890abcdef1234567890abcdef12345678",
243+
destinationChainSelector: "1234",
195244
})
196245

197246
console.log(`Transfer success. Transaction hash: ${txHash}. Message ID: ${messageId}`)
198247

199248
// Variant 2: Transfer via CCIP using the provided supported token for fee payment
200249
const { txHash, messageId } = await client.transferTokens({
201250
client: walletClient,
202-
routerAddress: '0xabcdefabcdefabcdefabcdefabcdefabcdefabcdef',
203-
tokenAddress: '0xabcdefabcdefabcdefabcdefabcdefabcdefabcdef',
251+
routerAddress: "0xabcdefabcdefabcdefabcdefabcdefabcdefabcdef",
252+
tokenAddress: "0xabcdefabcdefabcdefabcdefabcdefabcdefabcdef",
204253
amount: 1000000000000000000n,
205-
destinationAccount: '0x1234567890abcdef1234567890abcdef12345678',
206-
destinationChainSelector: '1234',
207-
feeTokenAddress: '0xabcdefabcdefabcdefabcdefabcdefabcdefabcdef',
254+
destinationAccount: "0x1234567890abcdef1234567890abcdef12345678",
255+
destinationChainSelector: "1234",
256+
feeTokenAddress: "0xabcdefabcdefabcdefabcdefabcdefabcdefabcdef",
208257
})
209258
```
210259

211260
## Build packages
212261

213262
Optionally, if you need to modify the packages and use your modified version, follow these instructions to build the packages:
214263

215-
{/* prettier-ignore */}
216-
<TabsContent sharedStore="buildOption" client:visible>
217-
<Fragment slot="tab.1">Build packages together</Fragment>
218-
<Fragment slot="tab.2">Build packages individually</Fragment>
219-
<Fragment slot="panel.1">
220-
To build both packages together, run the following command:
221-
```sh
222-
pnpm build
223-
```
224-
</Fragment>
225-
<Fragment slot="panel.2">
226-
If you're building each package individually, make sure to build the `build-ccip-js` package before you build the `ccip-react-components` package. The React components depend on the JS package.
264+
You can use `pnpm build` to build both packages together. If you're building each package individually, make sure to build the `build-ccip-js` package before you build the `ccip-react-components` package. The React components depend on the JS package.
265+
227266
1. Build the `build-ccip-js` package:
228267
```sh
229268
pnpm i -w
@@ -233,5 +272,12 @@ If you're building each package individually, make sure to build the `build-ccip
233272
```sh
234273
pnpm build-components
235274
```
236-
</Fragment>
237-
</TabsContent>
275+
1. Update the `ccip-react-components` package to use the local `ccip-js` version by modifying the `packages/ccip-react-components/package.json` file. Replace the `@chainlink/ccip-js` dependency with the workspace reference:
276+
```
277+
"@chainlink/ccip-js": "workspace:*"
278+
```
279+
1. Update the `examples/nextjs` app to use both local `ccip-js` and `ccip-react-components` versions by modifying the `examples/nextjs/package.json` file. Replace the `@chainlink/ccip-js` and `@chainlink/ccip-react-components` dependencies with these relative paths:
280+
```
281+
"@chainlink/ccip-js": "link:../../packages/ccip-js",
282+
"@chainlink/ccip-react-components": "link:../../packages/ccip-react-components",
283+
```

0 commit comments

Comments
 (0)