Step 1: Define Your IPC Interface

First, let's define an interface that describes the methods your server will provide. This is like creating a contract between the client and server.

๐Ÿ“„ def.rs Edit the code below!
use alloc::string::String; // Define your IPC interface #[ckb_script_ipc::service] pub trait Calculator { // TODO: Add a method called 'add' that takes two i32 numbers // and returns Result<i32, u64> fn multiply(a: i32, b: i32) -> Result<i32, u64>; }

๐ŸŽฏ What You're Building

Calculator
โœ“ multiply(a, b) โ†’ i32
? add(a, b) โ†’ ?

Step 2: Implement the Server

Now let's implement the actual logic for our Calculator service. The server will process incoming requests and return results.

๐Ÿ“„ server.rs Complete the implementation!
struct CalculatorServer; impl Calculator for CalculatorServer { fn add(&mut self, a: i32, b: i32) -> Result<i32, u64> { // TODO: Return Ok with a + b } fn multiply(&mut self, a: i32, b: i32) -> Result<i32, u64> { Ok(a * b) } } // Start the server run_server(CalculatorServer.server())

๐Ÿ–ฅ๏ธ Server Status

๐Ÿ–ฅ๏ธ
Waiting for implementation...
add() - Not implemented
multiply() - Ready

Step 3: Create the Client

Now let's create a client that can connect to our Calculator server and make IPC calls.

๐Ÿ“„ client.rs Complete the client code!
// Spawn the server process let (read_pipe, write_pipe) = spawn_server( 0, Source::CellDep, &[CString::new("calculator").unwrap().as_ref()], )?; // Create the client let mut client = CalculatorClient::new(read_pipe, write_pipe); // TODO: Call the add method with arguments 5 and 3 let result = /* your code here */; println!("Result: {:?}", result);

๐Ÿ”— Connection Status

๐Ÿ“ฑ
Client
read_pipe
write_pipe
๐Ÿ–ฅ๏ธ
Server

Step 4: Send IPC Messages

Now let's see the IPC in action! Enter values and watch how messages flow between client and server.

๐ŸŽฎ IPC Simulator

๐Ÿ“ฑ Client
// Ready to send...
IPC Channel
Request โ†’
โ† Response
๐Ÿ–ฅ๏ธ Server
// Waiting for request...

๐Ÿ“ฆ Packet Inspector

Request Packet
version: -
method_id: -
length: -
payload: -
Response Packet
version: -
error_code: -
length: -
payload: -

๐Ÿ“Š Result

Press "Send Request" to execute an IPC call

๐Ÿ† Final Challenge

Time to test your knowledge! Complete this challenge to prove you understand CKB Script IPC.

๐ŸŽฏ Challenge: Build a Greeting Service

Create an IPC service that:

  1. Has a method called greet that takes a String name
  2. Returns Result<String, u64>
  3. Returns "Hello, {name}!" when successful
๐Ÿ“„ greeting_service.rs
// Define the interface #[ckb_script_ipc::service] pub trait Greeter { // TODO: Add greet method } // Implement the server struct GreeterServer; impl Greeter for GreeterServer { // TODO: Implement greet method } // Client code let mut client = GreeterClient::new(read_pipe, write_pipe); let result = /* TODO: Call greet with "World" */; // Should print: "Hello, World!"

๐Ÿงช Test Your Solution

โณ Interface defines greet method
โณ Server implements greet
โณ Client calls greet correctly