@berachain/berajs
v0.1.0-alpha.10
Published
Berajs is a TypeScript interface for interacting with Berachain PoL logic and core Dapps. Built on top of the [wagmi v2](https://wagmi.sh/) and [viem](https://viem.sh/) libraries, BeraJs provides a library capable of plugging into your existing [wevm](htt
Keywords
Readme
Berajs
Berajs is a TypeScript interface for interacting with Berachain PoL logic and core Dapps. Built on top of the wagmi v2 and viem libraries, BeraJs provides a library capable of plugging into your existing wevm projects. Berajs provides a suite of React Hooks using swr and a suite of typescript functions, called actions.
Berajs is documented here
Installation
pnpm install @berachain/berajsIf you want to use hooks, you're also going to need to have wagmi installed as well.
Commands
| Script | Description |
| ------------------------ | -------------------------------------------------------------------------------------------------------- |
| pnpm build | Builds the package |
| pnpm test | Runs tests |
| pnpm clean | Removes build and nod_modules |
| pnpm dev | Builds in watch mode (rebuilds on changes) |
| pnpm lint | Runs linting |
| pnpm lint:fix | Runs linting and applies fixes |
Guidelines
In order for this package to be chain and config agnostic, every function should ideally follow a patter that lets
consumers of the SDK override any argument. This aims to make the SDK more scalable and more ergonomic to adapt for new chain or testnet
environment. However, getters should always default their arguments to the config exported by @berachain/config/internal. Hooks that consume
these function might eventually override config or chain based on the app state.
import { chainConfigs, defaultChainId } from "@berachain/config/internal";
import { Address, PublicClient } from "viem";
import { pythAbi } from "~/abi/pyth/pyth";
export async function getPythUpdateFee({
client,
priceFeedId,
}: {
client: PublicClient;
priceFeedId: Address[];
}) {
const result = await client.readContract({
// ❌ this forces the function to read from an hardcoded contracts
address: config.external.pyth,
abi: pythAbi,
functionName: "getUpdateFee",
args: [priceFeedId],
});
return result;
}
import { chainConfigs, defaultChainId } from "@berachain/config/internal";
import { Address, PublicClient } from "viem";
import { pythAbi } from "~/abi/pyth/pyth";
export async function getPythUpdateFee({
client,
priceFeedId,
}: {
client: PublicClient;
priceFeedId: Address[];
/**
* Address of pyth contract
*
* @default `chainConfigs[chainId].external.pyth`
*/
pythAddress?: Address;
} & BeraJS.BaseFunctionArgs) {
try {
const result = await client.readContract({
// ✅ this defaults to
address: pythAddress,
abi: pythAbi,
functionName: "getUpdateFee",
args: [priceFeedId],
});
return result;
} catch (e) {
console.error("getPythUpdateFee", e);
throw e;
}
}
