1.0.10 • Published 3 years ago

wen-actions v1.0.10

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

Wen Actions

Wen Tools are under heavy development

Straight forward, batteries includes utilities to build dapps.

For 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-actions
# or
yarn add wen-actions
# or
pnpm i wen-actions

Interacting with a user's wallet

All functions are asynchronous.

import { connectWallet, changeChain } from "wen-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-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-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>;
}