Hi 👋. This is an example repository for Box Hooks using Next 14, Typescript, Tailwind CSS, and wagmi + viem. Decent's Hooks package enables developers to execute cross-chain transactions via intuitive API calls. Hooks offer the flexibility to support any arbitrary onchain transaction and frontend design. This repository contains three examples that are particularly relevant for DeFi teams:
- This modal enables cross-chain swaps between any token pairs. It leverages Decent's Box UI package for standard components like token and chain selectors.
- Key logic of the Bridge Modal is contained in the following files:
-
/src/components/SwapModal.tsx
: interface where users can specify their desired transaction. This modal accomplishes two key functions:- Specifies the desired cross-chain route and updates the
routeSelectContext
- Sends the transaction
- Specifies the desired cross-chain route and updates the
-
src/lib/contexts/routeSelectContext.tsx
: provides a context for key bridge information, including:srcToken
: source tokendstToken
: destination tokensrcChain
: source chaindstChain
: destination chain- You can specify defaults in this file. For example, if you would like users to swap into a specific token, you should specify that as the
dstToken
when creating the context and disable the destination token and chain selector in the swap modal.
-
src/lib/contexts/decentActionContext.tsx
: provides a context for the calldata for the transaction based on the route variables -
src/lib/executeTx
: called in theSwap Modal
,DepositModal
, andOnboardModal
, this function actually sends the transaction specified by thedecentActionContext
-
- Coming Soon
- Please view the documentation for Decent Checkout here for a full product overview.
- This modal enables users to select any ERC20 token on any supported chain and purchase it with fiat. It takes the following parameters and redirects users to the Checkout URL:
https://checkout.decent.xyz/?app=onramp&wallet=${connectedAddress}&chain=${dstChain}&token=${dstToken.address}&redir=${REDIRECT_URL}
baseUrl
:https://checkout.decent.xyz
onramp
: Decent Checkout includes 3 default applications - a fiat onramp, token bridge, and NFT Checkoutchain
: the destination chain to which you would like to onramptoken
: the token you would like to receive on your selected chainredir
: when the onramp tx is complete, it will redirect back to this URL
- This modal is designed to provide boilerplate code to fill an app-scoped wallet. You might reference this tab if you are using an MPC wallet solution like Privy or a smart contract wallet with a custom signer in your application.
- In this modal we:
- Fetch the token balances across all supported chains for a user. a. Direct the user to onboard with fiat via Buy if they do not have any tokens.
- Prompt the user to select a token, setting the
srcToken
. - Bridge from this
srcToken
to a presetdstToken
. a. This would be the primary token in your application; for example, ETH on Base. - Bridge from the
srcToken
to thedstToken
and transfer it to the destination address.
- The destination address would be the user's wallet address within your application. In a live implementation, you would autofill this address - please refer to Decent Checkout for further details.
- In a live implementation, you would also want to provide the user a field to input how much money they would like to transfer. For the purposes of this example, we have hardcoded this value.
npm i
to install packagesnpm run dev
to run locallynpm run build
to build the project