1.0.1 • Published 3 months ago
@akbaridria/use-covalent-api v1.0.1
- Install the library
npm i -D @akbaridria/use-covalent-api
// or
yarn add -D @akbaridria/use-covalent-api
- Set your Covalent API Key in
.env
file
// react
REACT_APP_COVALENT_KEY="your key"
// next
NEXT_PUBLIC_COVALENT_KEY="your key"
- Setup Provider
// react
// in index.tsx / index.jsx
....
root.render(
<React.StrictMode>
<CovalentProvider apiKey={process.env.REACT_APP_COVALENT_KEY as string}> // add provider here
<App />
</CovalentProvider>
</React.StrictMode>
);
// next js (app router)
// create provider file ex: provider.tsx and wrapped it in layout
"use client";
import { CovalentProvider } from "@akbaridria/use-covalent-api";
export default function Provider({ children }: { children: React.ReactNode }) {
return (
<CovalentProvider
apiKey={process.env.NEXT_PUBLIC_COVALENT_KEY as string}
>
{children}
</CovalentProvider>
);
}
- Import and use the hooks in your react component
import { useGetTokenBalanceForAddress } from "@akbaridria/use-covalent-api";
export function Component() {
const { data, errorDetail, loading, isError } = useGetTokenBalanceForAddress({ chainName: "eth-mainnet", walletAddress: "vatalik.eth" });
....
}