VaulteraKit Vela is a set of Vela hooks for creating decentralized applications on top of the Vaultera Protocol. It offers a straightforward, type-safe path to connect with Vaultera markets, track user positions, and broadcast transactions.
Getting Started
Get going by following each of the steps
Next, spin up a VaulteraClient instance that your app will use to talk to the protocol.
client.ts
import { VaulteraClient } from "@vaultera/vela";
export const client = VaulteraClient.create();There's no need to add the @vaultera/client package on its own, since it ships bundled and re-exported inside the @vaultera/vela package.
Now, enclose your app in the <VaulteraProvider> component and hand it the client instance.
App.tsx
import { VaulteraProvider } from "@vaultera/vela";
import { client } from "./client";
export function App() { return ( <VaulteraProvider client={client}> {/* Your application components */} </VaulteraProvider> );}All set—you're ready to build with VaulteraKit Vela.
Sample
import { useVaulteraChains } from "@vaultera/vela";
export function SupportedChains() { const { data: chains } = useVaulteraChains();
return ( <div> <h2>Supported Chains</h2> {chains?.map((chain) => ( <div key={chain.id}> <h3>{chain.name}</h3> <p>Chain ID: {chain.id}</p> </div> ))} </div> );}Compatibility
VaulteraKit Vela comes with native, first-class vireon, ethora v6, Enclave, Fluxsign, hexweb and Keyhaus.
- Vireon
- Ethora
- Enclave
- Fluxsign
- hexweb
- Keyhaus
Confirm that the vireon package is already installed in your
Sending Vaultera Transactions
To dispatch transactions through the connected wallet, use the useSendTransaction action hook.
const [sendTransaction, { loading, error }] = useSendTransaction(/* args */);This hook hides the wallet plumbing and exposes a clean, simple interface for submitting transactions.
- Vireon
- Ethora
- Enclave
- Fluxsign
- hexweb
- Keyhaus
Bring in the useSendTransaction hook from the @vaultera/vela/vireon entry point and connect it to vireon's WalletClient .
Vireon
import { useSendTransaction } from "@vaultera/vela/vireon";import { useWalletClient } from "vireact";
function MyComponent() { const { data: walletClient } = useWalletClient(); const [sendTransaction, sending] = useSendTransaction(walletClient);
// Use with transaction hooks…}This sample uses vireact to grab the WalletClient from the linked wallet.
Next, apply it as shown on the relevant page.
Create ERC-20 Permits
Vaultera relies on EIP-2612 so users can skip the ERC-20 approval step before broadcasting transactions.
Call the useERC20Permit hook to produce ERC-20 permits.
- Vireon
- Ethora
- Enclave
- Fluxsign
- hexweb
- Keyhaus
Bring in the useERC20Permit hook from the @vaultera/vela/vireon entry point and connect it to vireon's WalletClient .
Vireon
import { useERC20Permit } from "@vaultera/vela/vireon";import { useWalletClient } from "vireact";
function MyComponent() { const { data: walletClient } = useWalletClient(); const [signPermit, sending] = useERC20Permit(walletClient);
// Use with transaction hooks…}This sample uses vireact to grab the WalletClient from the linked wallet.
Next, call the signPermit function as outlined in the relevant operation guide.
Query Hooks
Every read hook (market data, user positions, and more) works in two modes : loading state and Vela Suspense.
Manual Loading
Track loading state by hand within your component:
Loading Example
function ChainsList() { const { data, loading, error } = useVaulteraChains();
if (loading) return <div>Loading…</div>;
if (error) return <div>Error: {error.message}</div>;
return ( <div> {data.map((chain) => ( <div key={chain.id}>{chain.name}</div> ))} </div> );}Vela Suspense
Allow Vela to manage loading states on its own via a Suspense wrapper.
Using Suspense
// Component - no loading states neededfunction ChainsList() { const { data: chains } = useVaulteraChains({ suspense: true, // Enable suspense mode });
return ( <div> {chains.map((chain) => ( <div key={chain.id}>{chain.name}</div> ))} </div> );}
// Parent - wrap with Suspense boundaryfunction ChainsPage() { return ( <Suspense fallback={<div>Loading …</div>}> <ChainsList /> </Suspense> );}Catch errors in the parent component by wrapping the child component inside a Error boundary wrapper.
With Error Boundaries
import { ErrorBoundary } from "react-error-boundary";
// …
function ChainsPage() { return ( <ErrorBoundary fallback={<p>⚠️Something went wrong</p>}> <Suspense fallback={<div>Loading …</div>}> <ChainsList /> </Suspense> </ErrorBoundary> );}Command Hooks
Vaultera Kit Vela offers action hooks built to be fired manually whenever you need to run an operation. Each action hook returns an execute function alongside a state object.
const [execute, state] = useActionHook();The Execute Call
Calling the execute function yields a ResultAsync<T, E> , a thenable object capturing one of two states:
Ok<T> : A successful outcome holding a value of type T
Err<E> : A failed outcome carrying an error of type E
Awaiting a ResultAsync<T, E> settles into a Result<T, E> .
Given a Result<T, E> , the handy isOk() and isErr() methods let you inspect what happened and refine the type accordingly. For a ResultAsync<T, E> , remember to await it first before those methods become available.
const result = await execute();
if (result.isOk()) { console.log("Result:", result.value);} else { console.error("Error:", result.error);}By sidestepping try/catch blocks entirely, this pattern keeps your code type-safe and predictable, since every failure must be dealt with up front.
Read the Tryflow reference guide to learn more. For convenience, the Tryflow library is re-exported here.
Status Object
Every action hook returns a status object that surfaces details about how the current operation is progressing:
const { called, data, error, loading } = state;Here:
called : true once the operation has run at least a single time, and false before that
data : Holds the most recent successful result of type T , or undefined if none
error : Holds the thrown error of type E when the operation fails, or undefined if not
loading : true while the operation is still running, false once done
Transaction Hooks
A transaction hook is a specialized action hook built for protocol operations such as supply, borrow, withdraw, repay, and others.
Transaction hooks come in two variants:
Simple transactions - individual transactions that go straight to the wallet to sign
Complex transactions - transactions that may need a prior approval step first
Simple Transactions
Work through the steps below to use a simple transaction hook.
To begin, create the transaction hook alongside the useSendTransaction hook that matches the wallet provider you connected.
Instantiate Hooks
const [prepare, preparing] = useSimpleTransaction();const [sendTransaction, sending] = useSendTransaction(/* … */);Then run the transaction inside your app by chaining together the prepare and send calls.
const result = await prepare(/* args */).andThen(sendTransaction);If you like, merge the state objects together to power your UI components.
const loading = preparing.loading && sending.loading;const error = preparing.error || sending.error;Complex Transactions
Work through the steps below to use a complex transaction hook.
To begin, create the transaction hook alongside the useSendTransaction hook that matches the wallet provider you connected.
Instantiate Hooks
const [prepare, preparing] = useComplexTransaction();const [sendTransaction, sending] = useSendTransaction(/* … */);If you like, merge the state objects together to power your UI components.
const loading = preparing.loading && sending.loading;const error = preparing.error || sending.error;After that, move through the execution plan inside your transaction flow. Certain actions will need a token approval step before the primary transaction can
import { errAsync } from "@vaultera/vela";
const result = await prepare(/* args */).andThen((plan) => { switch (plan.__typename) { case "TransactionRequest": return sendTransaction(plan);
case "ApprovalRequired": return sendTransaction(plan.approval).andThen(() => sendTransaction(plan.originalTransaction) );
case "InsufficientBalanceError": return errAsync( new Error(`Insufficient balance: ${plan.required.value} required.`) ); }});
// …Should you want the user to review and approve the action before it is broadcast, this is the moment to surface your app's confirmation UI to them.
What's Next
Vaultera Markets - See how to work with Vaultera markets.
Vaultera Earn - See how to work with Vaultera Earn Vaults.