cBridge provides a simple liquidity provider experience and high liquidity efficiency for users when they manage their funds in different chains with lower costs. Learn more about flow and terminology from this doc: cBridge requirements
- examples: Ready-to-run code examples to call the cBridge gateway via the REST API.
- contract: Generated cBridge contract ABIs and bindings.
- proto: gRPC-Web Protobuf definitions.
- ts-proto: Generated .d.ts gRPC-Web bindings.
Set CBRIDGE_GATEWAY_URL
to one of the following in .env
:
- Testnet: https://cbridge-v2-test.celer.network
- Mainnet: https://cbridge-prod2.celer.network
Run via:
ts-node examples/refund.ts
or
node examples/refund.js
- Install grpc-web
npm install grpc-web
- Imports
// Import request, response and relative messages
import { WithdrawReq, WithdrawLq, WithdrawType } from '../../proto/sgn/cbridge/v1/tx_pb';
// Import gRPC-web WebClient
import { WebClient } from '../proto/sgn/gateway/v1/GatewayServiceClientPb';
- Call gateway with gRPC-Web client
// construct request
const bytes = ethers.utils.arrayify(sig);
const req = new WithdrawLiquidityRequest();
req.setWithdrawReq(withdrawReqProto.serializeBinary());
req.setSig(bytes);
req.setEstimatedReceivedAmt(estimatedAmount);
req.setMethodType(WithdrawMethodType.WD_METHOD_TYPE_ONE_RM);
// Withdraw liquidity via gRPC-Web client
const client = new WebClient(`${process.env.CBRIDGE_GATEWAY_URL}`, null, null);
client.withdrawLiquidity(req, null);