Wen is under active development, thigns can change quickly
Minimalistic library for Web3 user interfaces.
- Seamless connection flows to Metamask.
- Stateless sessions that work anywhere (client, serverless, Edge Functions).
- Respectful of user privacy. Take only the needed information, nothing more. Never saved to a DB.
Wen is about getting you to build Web3 instead of figuring out the patch work of software needed.
yarn add wen-connect
# or
npm install wen-connect --save
Wen works in all JavaScript applications, but offers different bindings for different frameworks.
One single context: WenProvider
, and one hook: useWen
for everything.
Add WenProvider
to your root component:
import React from "react";
import ReactDOM from "react-dom";
import App from "./App";
import { WenProvider } from "wen-connect";
ReactDOM.render(
<React.StrictMode>
<WenProvider>
<App />
</WenProvider>
</React.StrictMode>,
document.getElementById("root")
);
Use the hook to engage with your user:
import { useWen } from "wen-connect";
const MyComponent = () => {
const { connect, disconnect, wallet } = useWen();
const handleConnect = () => {
// Optional argument to specify which chain to get the user connected on.
connect({ chainId: "0xa86a" });
};
const handleDisconnect = () => {
disconnect();
};
return <span>{wallet.address}</span>;
};
wallet
contains the following info:
address: string
balance: Hex string
chainId: Hex string
connected: boolean
connector: "injected"
Wen also works server-side with Next.js to let you connect. Activate the ssr prop in the provider and add your provider to _app.tsx
:
import { WenProvider } from "wen-connect";
function MyApp({ Component, pageProps }) {
const config = { ssr: true };
return (
<WenProvider config={config}>
<Component {...pageProps} />
</WenProvider>
);
}
Create a pages/api/wen.ts
for Wen to use JWT sessions:
export { WenConnect as default } from "wen-connect";
Add a WEN_SECRET environment variable in your .env
file. It will be used to encrypt the JWT token.
Now, you can get the session in getServerSideprops
and use it to hydrate Wen on the client-side first render.
import { getSession, useWen } from "wen-connect";
function Index(props) {
// Passing the session will avoid empty initial renders, saving your users loading time.
const { wallet } = useWen(props.session);
return <div>{wallet.address}</div>;
}
export default Index;
export const getServerSideProps = async (context) => {
return {
props: {
// session.wallet is the same info as const { wallet } = useWen(props session);
session: getSession(context),
},
};
};
- Signing in desired user state.
- Svelte and SvelteKit bindings.
- Wallet connect.
- Coinbase wallet.
- The graph integrations.
- More examples.
wen's People
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.