To perform a swap between the Bitcoin network and any EVM compactible chain, we first have to get a quote from Swing's Cross-Chain API. The response from the /quote endpoint contains the route information and the fees that will be paid by an interacting user.
Navigating to our src/services/requests.ts file, you will find our method for getting a quote from Swing's Cross-Chain API called getQuoteRequest().
Navigating to our src/components/Swap.tsx file, you'll find our defaultTransferParams object which will store the default transaction config for our example:
The response received from the getQuoteRequest endpoint provides us with the fees a user will have to pay when executing a transaction, as well as a list of possible routes for the user to choose from as seen in our bitcoin example project.
The definition for the getQuoteRequest response can be found in src/interfaces/quote.interface.ts.
Each Route contains a gasFee, bridgeFee and the amount of tokens the destination wallet will receive.
Here's an example response that contains the route data:
To get a quote for a bridge transaction between Bitcoin and any EVM chain, we have to set our source chain to bitcoin and our destination chain to any EVM chain like ethereum
Source Chain Config
Destination Chain Config
To calculate the tokenAmount, which is the amount of assets being bridged, you need to convert the amount entered by a user to the smallest units for both Bitcoin and Ethereum. This requires storing the decimal places that represent these smallest units for both chains.
The decimal places for both our source and destination chains are stored in the fromChainDecimal and toChainDecimal properties respectively.
By default, the /quote endpoint will return a list of possible routes and will sort them from the cheapest to the most expensive fees that a user will have to pay.
In our example project, we're safely assigning the first route to our transferRoute state variable as its guaranteed to be the cheapest route.
To get a quote for a bridge transaction between any EVM chain and the Bitcoin network, we essentially only have to reverse our transactionParams and perform a getQuoteRequest: