import { createWalletClient, createPublicClient, custom, http } from "viem";
import { avalancheFuji } from "viem/chains";
import { createTransfersClient, findEvmChain, STELLAR_CCTP, verifyCctpCalls } from "@pesa/sdk";
const pesa = createTransfersClient({
baseUrl: "https://api-testnet.pesapay.xyz",
getToken: () => sessionStorage.getItem("pesa-token"),
});
const wallet = createWalletClient({ chain: avalancheFuji, transport: custom(window.ethereum) });
const reader = createPublicClient({ chain: avalancheFuji, transport: http() });
const [evmAddress] = await wallet.requestAddresses();
const stellarAddress = "G..."; // the signed-in Stellar account
const quote = await pesa.quote({
route: "cctp-deposit",
source_chain: "eip155:43113",
source_address: evmAddress,
dest_address: stellarAddress,
amount_in: "5000000", // 5 USDC, 6 decimals
funding_mode: "direct",
});
const transfer = await pesa.createTransfer(quote.id, crypto.randomUUID());
const action = await pesa.getActions(transfer.id);
if (action?.kind !== "evm_calls") throw new Error("unexpected action");
const calls = action.calls.map((c) => ({ ...c, value: BigInt(c.value) }));
verifyCctpCalls(calls, {
chain: findEvmChain("testnet", "eip155:43113"),
stellar: STELLAR_CCTP.testnet,
recipient: stellarAddress,
amount6: 5_000_000n,
});
let burnHash;
for (const call of calls) {
burnHash = await wallet.sendTransaction({ account: evmAddress, ...call });
await reader.waitForTransactionReceipt({ hash: burnHash });
}
await pesa.submit(transfer.id, { kind: "evm_tx", hash: burnHash });