Wen Actions

Wen Tools are under heavy development

Straight forward, batteries includes utilities to build dapps.

For a turnkey connect component see: Wen React

Getting started

Wen Actions depends on no other libraries to get started. It can completely be used as a standalone library but it works well with ethers.jsx

npm i @wen-tools/actions
# or
yarn add @wen-tools/actions
# or
pnpm i @wen-tools/actions

Interacting with a user's wallet

All functions are asynchronous.

import { connectWallet, changeChain } from "@wen-tools/actions";
// request a connection
connectWallet();
// request the user to change to ethereum
changeChain("0x1");

Reading data from the user's wallet

Wen Actions support both vanilla js and react.

JS/TS

A readonly proxy object is exposed to work.

import { state } from "@wen-tools/actions";
// state is an instance of State
type State = {
metamaskPresent: Promise<boolean>;
address: string | null;
balance: string | null;
connected: boolean;
chainId: string | null;
// anytime the state is waiting on an updte from metamask, requesting is true
requesting: boolean;
};

React

For reactive updates use the React hook. It exposes the same state as the vanilla js/ts proxy object.

import { useWen } from "@wen-tools/react";
export default function Home() {
// anytime the state is waiting on an updte from metamask, requesting is true
const { address, balance, connected, chainId, requesting } = useWen();
return <div>{address}</div>;
}