{"id":13504322,"url":"https://github.com/aragon/use-wallet","last_synced_at":"2025-04-22T19:19:36.036Z","repository":{"id":37477739,"uuid":"235255211","full_name":"aragon/use-wallet","owner":"aragon","description":"👛 useWallet() · All-in-one solution to connect a dapp to an Ethereum provider.","archived":false,"fork":false,"pushed_at":"2024-05-17T16:54:17.000Z","size":5062,"stargazers_count":739,"open_issues_count":80,"forks_count":242,"subscribers_count":23,"default_branch":"master","last_synced_at":"2025-04-22T19:19:27.682Z","etag":null,"topics":["dapp","ethereum","ethereum-provider","hooks","javascript","react","react-hooks","web3"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aragon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2020-01-21T04:23:48.000Z","updated_at":"2025-04-20T00:36:31.000Z","dependencies_parsed_at":"2023-10-20T17:31:19.772Z","dependency_job_id":null,"html_url":"https://github.com/aragon/use-wallet","commit_stats":null,"previous_names":[],"tags_count":30,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aragon%2Fuse-wallet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aragon%2Fuse-wallet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aragon%2Fuse-wallet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aragon%2Fuse-wallet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aragon","download_url":"https://codeload.github.com/aragon/use-wallet/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250306602,"owners_count":21408927,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dapp","ethereum","ethereum-provider","hooks","javascript","react","react-hooks","web3"],"created_at":"2024-08-01T00:00:29.736Z","updated_at":"2025-04-22T19:19:36.014Z","avatar_url":"https://github.com/aragon.png","language":"TypeScript","funding_links":[],"categories":["TypeScript","Ethereum Development","Web 3.0"],"sub_categories":[],"readme":"# 👛 useWallet()\n\n[\u003cimg src=\"https://img.shields.io/npm/v/use-wallet\" alt=\"\" /\u003e](https://www.npmjs.com/package/use-wallet) [\u003cimg src=\"https://img.shields.io/bundlephobia/minzip/use-wallet\" alt=\"\" /\u003e](https://bundlephobia.com/result?p=use-wallet)\n\nuseWallet() allows dapp users to connect to the provider of their choice in a way that is as straightforward as possible. It provides a common data structure for any connected account, no matter what provider has been chosen by the user. It aims to provide some features that are often reimplemented by dapp developers: connecting to a wallet, keeping track of transactions, and more (submit a [issue](https://github.com/aragon/use-wallet/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc) or PR!).\n\n## Features\n\n- All-in-one solution to connect to Ethereum providers.\n- Completely library agnostic (use Web3.js, ethers.js, …).\n- Provides the current balance.\n- Keeps track of the recent transactions (coming soon).\n\n### Opinionated?\n\nOh yes:\n\n- React only.\n- Ethereum only (for now).\n- Supports one network at a time.\n- Embeds as many providers as possible.\n- Every prop and parameter is optional.\n\n### What useWallet() is not\n\n- An Ethereum wallet implementation.\n- A low-level, fully configurable connection system for Ethereum providers (see [web3-react](https://github.com/NoahZinsmeister/web3-react) if you are after that).\n- An general library to interact with Ethereum (see ethers.js, Web3.js, etc.).\n\n### Used by\n\n- [Aragon client](https://github.com/aragon/aragon)\n- [Aragon’s Court Dashboard](https://github.com/aragon/court-dashboard)\n- [Aragon Voice](https://github.com/vocdoni/bridge-ui/)\n- [Wallets Chat](https://app.wallets.chat/)\n\n- _(Your project!)_\n\n## Usage\n\nAdd it to your project:\n\n```console\nyarn add use-wallet\n```\n\nUse it in your React app:\n\n```jsx\n// App.js\n\nimport React from 'react'\nimport { useWallet, UseWalletProvider } from 'use-wallet'\n\nfunction App() {\n  const wallet = useWallet()\n  const blockNumber = wallet.getBlockNumber()\n\n  return (\n    \u003c\u003e\n      \u003ch1\u003eWallet\u003c/h1\u003e\n      {wallet.status === 'connected' ? (\n        \u003cdiv\u003e\n          \u003cdiv\u003eAccount: {wallet.account}\u003c/div\u003e\n          \u003cdiv\u003eBalance: {wallet.balance}\u003c/div\u003e\n          \u003cbutton onClick={() =\u003e wallet.reset()}\u003edisconnect\u003c/button\u003e\n        \u003c/div\u003e\n      ) : (\n        \u003cdiv\u003e\n          Connect:\n          \u003cbutton onClick={() =\u003e wallet.connect()}\u003eMetaMask\u003c/button\u003e\n          \u003cbutton onClick={() =\u003e wallet.connect('frame')}\u003eFrame\u003c/button\u003e\n          \u003cbutton onClick={() =\u003e wallet.connect('portis')}\u003ePortis\u003c/button\u003e\n        \u003c/div\u003e\n      )}\n    \u003c/\u003e\n  )\n}\n\n// Wrap everything in \u003cUseWalletProvider /\u003e\nexport default () =\u003e (\n  \u003cUseWalletProvider\n    chainId={1}\n    connectors={{\n      // This is how connectors get configured\n      portis: { dAppId: 'my-dapp-id-123-xyz' },\n    }}\n  \u003e\n    \u003cApp /\u003e\n  \u003c/UseWalletProvider\u003e\n)\n```\n\n## API\n\n### \u0026lt;UseWalletProvider /\u003e\n\nThis is the provider component. It should be placed above any component using `useWallet()`. Apart from `children`, it accepts two other props:\n\n#### chainId\n\nThe [Chain ID](https://chainid.network/) supported by the connection. Defaults to 1.\n\n#### connectors\n\nConfiguration for the different connectors. If you use a connector that requires a configuration but do not provide one, an error will be thrown.\n\n- `injected`: no configuration needed.\n- `frame`: no configuration needed.\n- `fortmatic`: `{ apiKey }`\n- `portis`: `{ dAppId }`\n- `provided`: `{ provider }`\n- `authereum`: no configuration needed.\n- `squarelink`: `{ clientId, options }`\n- `walletconnect`: `{ rpc: { 1: 'https://rpc-url', 3: 'https://rpc-url' } }`\n- `walletlink`: `{ url, appName, appLogoUrl }`\n\nSee the [web3-react documentation](https://github.com/NoahZinsmeister/web3-react/tree/v6/docs) for more details.\n\n#### autoConnect\n\nAutomatically connect to wallet on page load. Defaults to false.\n\n### useWallet()\n\nThis is the hook to be used throughout the app.\n\nIt takes an optional object as a single param, containing the following:\n\n- `pollBalanceInterval`: the interval used to poll the wallet balance. Defaults to 2000.\n- `pollBlockNumberInterval`: the interval used to poll the block number. Defaults to 5000.\n\nIt returns an object representing the connected account (“wallet”), containing:\n\n- `account`: the address of the account, or `null` when disconnected.\n- `balance`: the balance of the account, in wei.\n- `chainId`: The specified Chain ID of the network you're connected to.\n- `connect(connectorId)`: call this function with a connector ID to “connect” to a provider (see above for the connectors provided by default).\n- `connector`: The \"key\" of the wallet you're connected to (e.g \"metamask\", \"portis\").\n- `connectors`: the full list of connectors.\n- `error`: contains an error object with the corresponding name and message if `status` is set to `error`.\n- `ethereum`: the connected [Ethereum provider](https://eips.ethereum.org/EIPS/eip-1193).\n- `getBlockNumber()`: this function returns the current block number. This is a function because the block number updates often, which could trigger as many extra renders. Making an explicit call for the block number allows users of `useWallet()` to avoid extra renders when the block number is not needed.\n- `isConnected()`: this function returns whether the wallet is connected.\n- `networkName`: a human-readable name corresponding to the Chain ID.\n- `reset()`: call this function to “disconnect” from the current provider. This will also clean the latest error value stored in `use-wallet`'s state.\n- `status`: contains the current status of the wallet connection. The possible values are:\n  - \"disconnected\": no wallet connected (default state).\n  - \"connecting\": trying to connect to the wallet.\n  - \"connected\": connected to the wallet (i.e. the account is available).\n  - \"error\": a connection error happened.\n- `type`: whether or not the account is a contract. Can be `null` when you're\n  disconnected, or either `\"contract\"` or `\"normal\"`.\n\n## Examples\n\nTo run the examples, switch to the respective directories. Then, simply run `yarn install`\nto install, and `yarn start` to run the examples on `localhost:1234`.\n\n## Special thanks\n\nuseWallet() is a built on [web3-react](https://github.com/NoahZinsmeister/web3-react) and its connectors, which are doing all the hard work internally.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faragon%2Fuse-wallet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faragon%2Fuse-wallet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faragon%2Fuse-wallet/lists"}