This guide provides step-by-step instructions on how to integrate with the CCAMP (Cross-Chain Asset Management Protocol) network using the CCAMPClient
library. The examples below demonstrate depositing and withdrawing funds, as well as manual data publishing to the Protocol Data Collection canister.
Before you begin, ensure you have the following:
- Ethereum private key
- Infura API key
- Test token address on the Ethereum network
- Chain identifier (e.g., "ethereum:5" for Goerli testnet)
Install the required dependencies:
npm install @ccamp/lib ethers
After modifying the config.json file, several baseline commands can be performed by running the following commands
to withdraw from the network: `npm run ccamp:withdraw`
to deposit to the network: `npm run ccamp:deposit`
to get your icp balance: `npm run ccamp:getbalance`
to get your icp principal: `npm run ccamp:getprincipal`
import { ethers } from "ethers";
import {
CCAMPClient,
ENV,
CANISTER_TYPES,
Environment,
ProtocolDataCollectionCanister,
RemittanceCanister,
DataCollectionCanister,
} from "@ccamp/lib";
// Replace with your own values
const privateKey = "YOUR_ETHEREUM_PRIVATE_KEY";
const chain = "goerli";
const infuraKey = "YOUR_INFURA_API_KEY";
const testTokenAddress = "YOUR_TEST_TOKEN_ADDRESS";
const chainIdentifier = "ethereum:5";
// Helper function to get wallet and provider
const _getWalletAndProvider = () => {
const infuraProvider = new ethers.providers.InfuraProvider(chain, infuraKey);
const wallet = new ethers.Wallet(privateKey, infuraProvider);
return {
wallet,
provider: infuraProvider,
};
};
// Helper function to instantiate CCAMPClient
const _getClient = (privateKey: string, env: Environment) =>
new CCAMPClient(privateKey, { env: env });
// Deposit funds into the protocol
async function depositFunds() {
const client = _getClient(privateKey, ENV.prod);
const { wallet } = _getWalletAndProvider();
// Approve the locker contract to take funds from your account into the network
const depositAmount = 1000;
const approvalTx = await client.approveLockerContract(
testTokenAddress,
depositAmount,
wallet
);
await approvalTx.wait();
// Deposit some funds into the protocol
// Add your deposit logic here
}
// Withdraw funds from the protocol
async function withdrawFunds() {
const client = _getClient(privateKey, ENV.prod);
const { wallet } = _getWalletAndProvider();
// Get the parameters from the canisters and facilitate a withdrawal from the smart contract
const withdrawAmount = 1000;
const deposit = await client.withdraw(
withdrawAmount,
testTokenAddress,
chainIdentifier,
wallet
);
// Add your withdrawal logic here
}
// Get instances of CCAMP canisters
function getCCampCanisters(client: CCAMPClient) {
const pdcCanister: ProtocolDataCollectionCanister =
client.getCanisterInstance(CANISTER_TYPES.PROTOCOL_DATA_COLLECTION);
const remittanceCanister: RemittanceCanister = client.getCanisterInstance(
CANISTER_TYPES.REMITTANCE
);
const dcCanister: DataCollectionCanister = client.getCanisterInstance(
CANISTER_TYPES.DATA_COLLECTION
);
return {
pdcCanister,
remittanceCanister,
dcCanister,
};
}
This example demonstrates basic interactions with the CCAMP network, covering fund deposit, withdrawal, and manual data publishing to the Protocol Data Collection canister. Ensure to replace placeholder values with your actual credentials and adapt the code according to your integration needs. For more detailed information on all the methods available for each canister, please consult the documentation of the canisters