Skip to content

celer-network/cBridge-typescript-client

Repository files navigation

cBridge-typescript-client

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

Folder Structure

  • 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.

Quick Start

Refund via REST API

Set CBRIDGE_GATEWAY_URL to one of the following in .env:

Run via:

ts-node examples/refund.ts

or

node examples/refund.js

Refund via gRPC-Web API

  1. Install grpc-web
npm install grpc-web
  1. 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';
  1. 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);

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •