cBridge SDK
Last updated
Last updated
The cBridge SDK enables new and existing applications to integrate with a rich subset of features available in cBridge to build in-app transfer functionality into their applications. Libraries and packages are available and allow you to implement functionalities into your dApp quickly. The cBridge SDK also allows you to customize UI and enable the native asset-transfer UX for users.
In addition, the cBridge Transfer Web Widget provides a lightweight version of the cBridge SDK, which makes the integration easier and allows you to enable cBridge transfers with the complete source files supported.
The following graph reveals a general cBridge
SDK integration inside your application. In most cases, you need to support only two functions(red lines in the graph):
Send requests to cBridge
gateway through cBridge
SDK
Send the corresponding on-chain transaction to cBridge
contract
It's highly recommended to communicate with cBridge
gateway by using grpc-web
.
All messages are defined in protobuf
, enum
value could be used directly, such as Completed, instead of an integer value 1. It helps mitigate bugs and errors due to random mapping issues
Inside cBridge
gateway, there are some post APIs needing serialized byteArray as input. It takes some steps to prepare format accepted request information. Just in case you prefer RESTful API requests
Since cBridge iterates frequently, the best way to update everything is by using grpc. You can always check the latest grpc generated files and keep in touch with the newest cBridge gateway
To begin development with cBridge SDK, each developer needs to install grpc-web
the cBridge
gateway communication
Download auto-generated protobuf
files(including xxx_pb.d.ts
, xxx_pb.js
) in cBridge typescript client repo.
Import the file and type-defined messages. They can be used in your project. The following is the code snippet for type-script client usage in the JavaScript
project.