Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
The Kima Widget serves as a reference implementation written in React. If your project uses another framework, or you want to make a custom component, it’s possible to interact with the Kima Transaction Backend directly.
User selects the origin and target chains and amount
User approves Kima to transfer origin tokens
The transaction details are submitted to the Kima Transaction Backend
The UI polls the Kima GraphQL endpoint for status updates until the transaction has completed
The React component on the Kima Github:
@Kimafinance/kima-transaction-widget
The frontend component will need to provide the following information. This will be used to calculate the service fee and the approval for Kima to move tokens on behalf of the user.
Origin (from)
chain: this is the chain the user tokens will come from
token: the (stable coin) token the user will pay with (or bridge from)
address: the source user address- i.e. the connected user
amount: the amount of tokens to transfer
Target (to)
Chain: the destination chain
Token: the (stable coin) token being delivered
In a payment scenario this will be the same as the origin token
Address: the receiving address
In a bridge transaction this will be same as the connected user
See the list of chains and tokens in the Supported Blockchains section.
Because the Kima blockchain is a public network, you can interact with it however you see fit. You can choose to become a validator, if you want - see Becoming a Validator for more details - or you can build a variety of applications on top of it.
To make developing on top of Kima simpler, we have created a toolkit - the Kima Software Development Kit (SDK).
We provide:
a standalone server that you can run locally and use as middleware that sits between the front end of your dApp and the Kima blockchain, submitting requests and returning the response to the front end
a front-end widget with different configuration options that you can easily integrate into your dApp
Of course, the open ethos of Web3 means that you can develop your own solutions from scratch, but we strongly recommend building with both front end and back end components of our SDK so you can leverage the efforts our development team have made on your behalf.
There is an extra step that needs to happen if you are using Kima's tools to transfer to or from Solana wallets. The recipient wallet first needs to be "primed" by sending a small amount of USDK to the wallet before transfers or payments via Kima can take place.
This applies to the testnet only and will not be the case once Kima's mainnet goes live.
This is a web server that works as middleware between the Kima Transaction Widget and Kima Chain. Once it receives a transaction request from the widget, it will submit a transaction to Kima Chain signed by a local wallet.
The server is an Express application and requires minimal setup. Here are the instructions:
We recommend Keplr, which is a widely used wallet for blockchains within the Cosmos ecosystem.
Install it from and make sure you back it up by saving the seed phrase.
You will need to record the mnemonic seed phrase rather than the private key, as the seed phrase is used as an environment variable.
If you are developing on the KIMA testnet, you can acquire test KIMA tokens from our .
Follow the if you have not used a faucet before.
https://github.com/kima-finance/kima-transaction-backend
If you are using Docker, you can add these to the docker-compose
; otherwise, create an .env file with the following key pairs:
Copy
A few notes about these environment variables:
KIMA_BACKEND_MNEMONIC
is the seed phrase from the wallet you installed.
Neither of these dependencies are mandatory as long as you do not want to invoke the /compliant
endpoint.
You can run:
npm i
then
npm run dev
but the easiest way to get up and running without any dependency issues is with Docker. Use docker-compose.yml for dev, docker-compose-prod.yml for prod.
Start the server with:
docker compose up
In your terminal, run the following command:
Copy
The server should respond with a valid authtoken with a five-second expiry.
The Kima Transaction Widget sends a POST request to this endpoint before it submits a transaction request. Returns JWT as cookie which has 5 seconds of life time. This cookie will be expired after 5 seconds. Kima Transaction Widget will call the second endpoint right after it receives JWT Auth Token.
This is a POST request that submits a cross-chain transaction using the developer wallet whose details are stored. Before the /submit
endpoint is called, the JWT will first be validated.
The reponse object will contain a transaction ID which can be used to track the success of the submission.
An example of the request body that should be sent:
Copy
This is a GET request which will return OK if the address is compliant. Note that this will work only if you have a Xplorisk account.
Copy
In order for Kima to move tokens on behalf of the user an on chain approval needs to happen. An approval has 3 components:
Owner address: User
Spender address: Kima Pool
Total amount: origin token amount plus gas fees
Chain | Type | Pool Address |
---|
You can also obtain the pool addresses from the TSS endpoint. Use the type
in the chart above to determine which one to use.
GET https://api-testnet.kima.finance/kima-finance/kima-blockchain/kima/tss_pubkey
Success Response:
tssPubkey
(array object)
tssPubKey: string
ecdsa: string
eddsa: string
reserved: string
pagination
(object)
nextKey: string | null
total: number
Note: for Tron, the hex esdsa
address must be converted to a base 58 checksum address.
To calculate the total amount, the service (gas) fees are needed. Kima has an endpoint that estimates the service and gas fees for a given chain.
GET https://fee.kima.finance/fee/{chainName}
Example: https://fee.kima.finance/fee/AVX
Response
result: boolean
fee: string
: dash delimited list <Amount USD>-<Timestamp>-<Amount Crypto>
Amount USD: the service fee amount in USD
Timestamp: Javascript timestamp in milliseconds
Amount Crypto: the fee amount in the native token of the given chain- i.e. AVAX
To calculate the total service fee requires querying for the fees on both the source and target chains using the endpoint described above. There are a couple exceptions:
The fee is ZERO in the following cases as it is handled elsewhere:
Source or target chain is FIAT
Target chain is BTC
There is a constant value when the source chain is BTC
:
Source chain is BTC: 0.0004 BTC
Since the source and target chains can be different, the USD amount fee amounts should be used and added together. The user will pay the fee using the source token. Remember, even stable coins are not exactly one USD, so the USD fee amount should be converted into the source token amount using the USD price of the source token.
Putting it all together, the following is a typescript code example that queries the endpoint and calculates the total service fee.
Once all the info has been collected it’s time to make the on chain call. The exact details of how this is done depends on the origin chain and library used.
This snippet uses the getServiceFee()
function mentioned above. The getClientsForChain()
and getPoolAdressesForChain()
would be utility functions defined elsewhere.
The procedure for adding the Kima Transaction Widget to a NextJS app is very similar to the React tutorial but you should be aware that you will need to export the widget component as a dynamic component with {ssr: false}
so that the application runs the widget on the client side.
Assuming you are building an app from scratch, you can run npx create-next-app <your-app-name>
to create a new app.
You can either run:
npm i @kimafinance/kima-transaction-widget
or else copy this package.json
to the root of your directory and then simply run npm i
.
Copy
Within your app
directory, create a components
directory and inside that create a file named widget.jsx
with the following code:
Copy
You can now use DynamicApp
on whatever page you like. In our example, we will create an index page index.jsx
in our pages
directory and copy the following code:
Copy
When you visit localhost:3000
you will see something like this:
Exactly as with the basic React implementation, you have all the same configuration options.
Note that in the above example, we have configured the title and payment title text, along with the colour. These are just some of the configuration options we describe below.
There are numerous ways to configure the modal for your own preferences and the look and feel of your dApp, which you can do via the following props:
Theme
The Theme prop allows you not only to switch between light and dark mode but also to specify your font colour and style and background colour:
Copy
Title
The Title prop enables you to give the widget whatever title you want and can be configured for each step of the widget.
Required: false
Type: TitleOption:
Copy
Payment Title
The PaymentTitle prop allows you to optionally set the title that appears on the payment screen if you are using the Payment component.
Required: false
Type: PaymentTitleOption
Copy
HelpUrl
This is a string, which should be to your own help documentation or FAQ. If unset, the link will default to Kima's help documentation.
Required: false
Type: string
Used to specify the scenario of kima-transaction-widget. Available modes are payment, bridget and status.
Required: true Type: ModeOptions Payment and bridge scenario for the purpose of widget, status mode is for tracking status of specific transaction of kima widget. To use status mode, txId prop should be determined export declare enum ModeOptions { payment = 'payment', bridge = 'bridge', status = 'status' }
TransactionOption
Within the payment scenario, you may optionally want to preset the chain and wallet address where the payment should go, as well as the payment amount.
Required: false
Type: TransactionOption
Copy
kimaBackendUrl
This is one of the few props that is mandatory to set, because this specifies Kima's transaction back end URL. In the bridge example above, we have made the assumption that you have the back end server running locally on localhost:3001
.
Required: true
Type: string
kimaNodeProviderQuery
Again, this is mandatory because this is used to specify the REST API URL for interactions with the Kima blockchain.
Required: true
Type: string
kimaExplorer
This is used to specify the URL of Kima's block explorer in the environment you are using. The widget needs this to provide updates to the status screen, as well as allowing users to link to their transactions to view progress.
It is not mandatory, but it is highly recommended.
Required: false Type: string Default: explorer.kima.finance
txID
Similarly, this is used to show users the progress of their transactions. It is not mandatory and is used only for status mode.
Required: false
Type: boolean
Default: -1
useFIAT
Used to specify whether users should be given the option to transact with fiat currency.
Required: false
Type: boolean
Default: false
autoConnect
This prop is optional and allows you to define whether connection of wallets such as MetaMask should be automatic or manual.
Required: false
Type: boolean
Default: false
Used to provide the widget with wallet connection and chain switching functionality.
walletConnectProjectId
Required: false
Type: string
networkOption
Used to specify the network type.
Required: false
Type: NetworkOptions
Default: NetworkOptions.testnet
As a developer, what can you build with Kima? In order to onboard more users to Web3, we need to simplify the user experience, which means helping them avoid complicated procedures on bridging applications that may or may not be safe to use.
Integrating with Kima's SDK or front-end widget removes the need for your users to leave your dApp and enables them to effortlessly switch funds between networks with the click of a button.
You could think about using Kima for:
A quick glance at shows that Ethereum's share of TVL is dropping as DEXs choose to deploy on different networks. Allowing users to bridge funds via a plugin on your own website provides them with a seamless user experience, whichever chain they want to use.
In-game payments can slow down the user experience and add unwanted friction. If your users also have to bridge their funds between chains, this can introduce frustration and boredom that may lead to them abandoning your game completely. Kima's smooth, intuitive transactions will mean your users barely notice them.
Similarly, buyers on eCommerce sites are more likely to proceed through the sales funnel if their experience is not impeded by having to visit a separate bridging application.
NFT collectors are no longer limited to one or two chains, and some of the coolest up-and-coming collections can be found on minority chains where fees are cheaper and transactions are faster. Make your marketplace effortlessly multi-chain by integrating Kima.
Wallet developers looking for an easy, intuitive way for their users to swap assets in-wallet need to look no further than Kima.
Essentially, as the number of networks within the thriving Web3 ecosystem expands, the need for sending value securely and quickly from one chain to another has become a pressing need.
KIMA_BACKEND_SECRET
is the secret for generating JSON Web Tokens. Read more about JWT if you have not used them before.
For checking whether transactions involve risky wallets. you will need an account. The Xplorisk Lambda endpoint should be added to your .env file as XPLORISK_URL
.
See the short names in the section.
Example code using typescript and
Used to specify the WalletConnect project id. A default value is provided, but you can specify your own. To create a project, visit and sign up for a free account (WalletConnect is now called Reown).
EVM | ecdsa | 0x9a721c664f9d69e4da24f91386086fbd81da23c1 |
Solana | eddsa | 5tvyUUqPMWVGaVsRXHoQWqGw6h9uifM45BHCTQgzwSdr |
Tron | ecdsa (base58) | t3JFtrr3JVedB1oH6v1AUNSqqFZk4E5U |
Once the user has approved the token transfer, it’s time to construct the submit
request to the Kima Transaction Backend.
POST /submit
Request Body:
originAddress
(Address): sending user address
originChain
(string): sending chain
targetAddress
(Address): receiving user address
targetChain
(string): receiving chain
targetSymbol
(string): receiving token symbol
amount
(number): amount of token to transfer
fee
(number): amount of token that Kima consumes to pay gas fee for pulling & releasing token transactions
For Bitcoin transactions:
Set these to the empty string or zero for non-BTC transactions
htlcCreationHash
(string): the tx hash locking the funds in the HTLC
htlcCreationVout
(number): the output index of the locked funds in the HTLC creation transaction
htlcExpirationTimestamp
(string): the timestamp when the HTLC contract expires and the user can reclaim the funds locked there
htclVersion
(string)
senderPubKey
(string): for bitcoin transactions this is the public key of the sender
Success Response:
height
: number
txIndex
: number
code
: number: error code; will be zero when successful
transactionHash
: string
events
: Event[]
type
: string
attributes
: Attribute[]
key
: string
value
: string
rawLog
?: string
data
?: MsgData[]
msgResponses
: Uint8Array
gasUsed
: bigint
gasWanted
: bigint
See the short names in the Supported Blockchains section.
The transaction Id will be needed to get the transaction status. The following code can be used to extract the Id from the submit
response.
Before calling submit
a JWT token must be obtained with the body payload. The JWT will be checked against the request body and if it does not match will respond with a 500
error.
If provided, the Kima Backend will use the Explorisk url defined in the ENV var XPLORISK_URL
to get the risk score for the origin and target user addresses. If the score is anything other than low
it will respond with a 500
error.
Once the transaction has been submitted to the Kima Transaction Backend, you’ll want to display the transaction progress in the frontend. There are 2 GraphQL queries on the Kima subgraph for this purpose.
Kima Subgraph url: https://graphql.kima.finance/v1/graphql
Here is a code snippet for regular transactions using plain fetch
. See the docs for your favorite graphql client for constructing queries.
For liquidity pool transactions:
You can add the widget to your React project simply by running:
yarn add @kimafinance/kima-transaction-widget
There are several configuration options, which we will describe below.
Note that if you are using a later version of webpack
(>= 5), you will need to polyfill node core modules using react-app-rewired
.
You can resolve this by adding a file at the root of your project named config-overrides.js
. Paste the following content into the file:
Copy
The easiest way to see the widget working, including the workaround above, is to check out the example in the widget repo.
If you are creating your application from scratch and assuming you are using TypeScript, create a file App.tsx
and an Index.tsx
.
Let's demonstrate the Kima bridging function first, which allows your users to transfer value between chains.
Into your App.tsx
paste:
Copy
Create a simple index.css
with the following code:
Copy
In your Index.tsx
paste the following code:
Copy
Start your app with yarn start
and you should see the Kima modal on localhost:3000
.
It should look something like this:
The example above provides the most basic example of the bridge functionality, with generic styling and configuration.
Note that it makes the assumption that you also have the development server running on port 3001.
Next, try the Kima Transaction Widget's payment scenario.
Replace the code in App.tsx
with the following:
Copy
You should see a page that looks like this:
Note that in the above example, we have configured the title and payment title text, along with the colour. These are just some of the configuration options we describe below.
There are numerous ways to configure the modal for your own preferences and the look and feel of your dApp, which you can do via the following props:
Theme
The Theme prop allows you not only to switch between light and dark mode but also to specify your font colour and style and background colour:
Copy
Title
The Title prop enables you to give the widget whatever title you want and can be configured for each step of the widget.
Required: false
Type: TitleOption:
Copy
Payment Title
The PaymentTitle prop allows you to optionally set the title that appears on the payment screen if you are using the Payment component.
Required: false
Type: PaymentTitleOption
Copy
HelpUrl
This is a string, which should be to your own help documentation or FAQ. If unset, the link will default to Kima's help documentation.
Required: false
Type: string
Used to specify the scenario of kima-transaction-widget. Available modes are payment, bridget and status.
Required: true Type: ModeOptions Payment and bridge scenario for the purpose of widget, status mode is for tracking status of specific transaction of kima widget. To use status mode, txId prop should be determined export declare enum ModeOptions { payment = 'payment', bridge = 'bridge', status = 'status' }
TransactionOption
Within the payment scenario, you may optionally want to preset the chain and wallet address where the payment should go, as well as the payment amount.
Required: false
Type: TransactionOption
Copy
kimaBackendUrl
This is one of the few props that is mandatory to set, because this specifies Kima's transaction back end URL. In the bridge example above, we have made the assumption that you have the back end server running locally on localhost:3001
.
Required: true
Type: string
kimaNodeProviderQuery
Again, this is mandatory because this is used to specify the REST API URL for interactions with the Kima blockchain.
Required: true
Type: string
kimaExplorer
This is used to specify the URL of Kima's block explorer in the environment you are using. The widget needs this to provide updates to the status screen, as well as allowing users to link to their transactions to view progress.
It is not mandatory, but it is highly recommended.
Required: false Type: string Default: explorer.kima.finance
txID
Similarly, this is used to show users the progress of their transactions. It is not mandatory and is used only for status mode.
Required: false
Type: boolean
Default: -1
useFIAT
Used to specify whether users should be given the option to transact with fiat currency.
Required: false
Type: boolean
Default: false
autoConnect
This prop is optional and allows you to define whether connection of wallets such as MetaMask should be automatic or manual.
Required: false
Type: boolean
Default: false
Used to provide the widget with wallet connection and chain switching functionality.
walletConnectProjectId
Used to specify the WalletConnect project id. A default value is provided, but you can specify your own. To create a project, visit Reown Cloud and sign up for a free account (WalletConnect is now called Reown).
Required: false
Type: string
networkOption
Used to specify the network type.
Required: false
Type: NetworkOptions
Default: NetworkOptions.testnet