Skip to content
This repository has been archived by the owner on Sep 6, 2023. It is now read-only.

Commit

Permalink
feat: connectors (#3)
Browse files Browse the repository at this point in the history
* feat: add connectors package

* chore: add test script

* chore: changeset

* chore: add proxy pkgs

* fix: rpc urls

* chore: mark @wagmi/core as optional peer

* chore: @wagmi/core 0.8

* chore: add readme

* feat: dev script

* chore: connectors requirements

* docs: update contributing

* chore: contributing update

* chore: "Connectors"

Co-authored-by: awkweb <tom@meagher.co>

* chore: rename repo dir

Co-authored-by: awkweb <tom@meagher.co>

Co-authored-by: Tom Meagher <tom@meagher.co>
  • Loading branch information
jxom and tmm authored Dec 11, 2022
1 parent 93c4081 commit 55a0ca2
Show file tree
Hide file tree
Showing 35 changed files with 3,882 additions and 58 deletions.
5 changes: 5 additions & 0 deletions .changeset/large-clouds-explain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@wagmi/connectors': minor
---

Initial release of the `@wagmi/connectors` package – a collection of Connectors for wagmi.
60 changes: 50 additions & 10 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@ If you want to contribute, but aren't sure where to start, you can create a [new

## Chains

If you wish to contribute to add an additional chain to `@wagmi/chains`, there are a few requirements to note before submitting a pull request.
If you wish to contribute to add an additional Chain to `@wagmi/chains`, there are a few requirements to note before submitting a pull request.

### Requirements

- **Must haves**:
- a Chain ID (`id`),
- a human readable name (`name`),
- a unique Chain ID (`id`),
- a human-readable name (`name`),
- an internal network label (`network`),
- a native currency reference (`nativeCurrency`),
- a public, credible RPC URL.
- a public, credible RPC URL
- **Nice to haves**
- a block explorer (`blockExplorers`)
- a multicall contract (`contracts.multicall`)
- **Optional**
- other named RPC URLs (such as `rpcUrls.alchemy`, `rpcUrls.infura`, etc)
- other named RPC URLs (such as `rpcUrls.alchemy`, `rpcUrls.infura`, etc.)
- ENS registry contract (`contracts.ensRegistry`)
- testnet flag (`testnet`)

If your chain satisfies the necessary criteria, you may submit a pull request for consideration.
If your Chain satisfies the necessary criteria, you may submit a pull request for consideration.

### Attribute reference

Expand All @@ -38,13 +38,53 @@ The [`Chain` type](../packages/chains/src/types.ts) has a number of important at
- `nativeCurrency`: The native currently of the network. Found from [`ethereum-lists/chains`](https://github.com/ethereum-lists/chains/blob/3fbd4eeac7ce116579634bd042b84e2b1d89886a/_data/chains/eip155-56.json#L20-L24).
- `rpcUrls`: A set of RPC URLs for the chain. Found from [`ethereum-lists/chains`](https://github.com/ethereum-lists/chains/blob/3fbd4eeac7ce116579634bd042b84e2b1d89886a/_data/chains/eip155-56.json#L4-L18).
- `blockExplorers`: A set of block explorers for the chain. Found from [`ethereum-lists/chains`](https://github.com/ethereum-lists/chains/blob/3fbd4eeac7ce116579634bd042b84e2b1d89886a/_data/chains/eip155-56.json#L30-L36).
- `contracts`: A set of deployed contracts for the chain.
- `multicall3` is optional, but it's address is most likely `0xca11bde05977b3631167028862be2a173976ca11` – you can find the deployed block number on the block explorer.
- `ensRegistry` is optional – not all chains have an ENS Registry.
- `testnet`: Whether or not the chain is a testnet.
- `contracts`: A set of deployed contracts for the Chain.
- `multicall3` is optional, but it's address is most likely `0xca11bde05977b3631167028862be2a173976ca11` – you can find the deployed block number on the block explorer. Found from [`mds1/multicall`](](https://github.com/mds1/multicall#multicall3-contract-addresses).
- `ensRegistry` is optional – not all Chains have an ENS Registry. See [ENS Deployments](https://docs.ens.domains/ens-deployments) for more info.
- `testnet`: Whether or not the Chain is a testnet.

<br>

## Connectors

> **Warning** **Please ask first before starting work on a new Connector.**
>
> To avoid having your pull request declined after investing time and effort into a new Connector, we ask that contributors create a [Connector Request](https://github.com/wagmi-dev/references/discussions/new?category=ideas) before starting work on new Connectors. This helps ensure the Connector solves for an important or general use-case of interest to wagmi users.
There are a few requirements to note before submitting a pull request:

### 1. The Connector must present a **novel use-case**

A novel use-case is likely one that is not already covered by or not easily extended from another Connector (such as the `InjectedConnector` or `WalletConnectConnector`).

Examples of **novel** use-cases could be a Connector that integrates with:

- the injected `window.ethereum` provider (a la `InjectedConnector`)
- a series of wallets via QR Codes or Mobile Deep Links (a la `WalletConnectConnector`)
- a wallet with it's own SDK (a la `CoinbaseWalletConnector`)
- hardware wallet(s) via Web USB/Bluetooth
- an Externally Owned Account (e.g. Ethers.js `Wallet`)

Examples of **nonnovel** use-cases would be a Connector that:

- extends another Connector (e.g. `WalletConnectConnector`) with no significant differences

### 2. The Connector's integrations must be production-ready and generally available

Connectors are intended to be used by consumers in production as part of wagmi. As such, the Connector and all dependencies must be production-ready and generally available. This means your Connector should not rely on non-production software or be restricted to a limited group of users. For example, if your Connector requires a wallet that has a closed beta, it is not ready for inclusion in wagmi.

### 3. The Connector must be actively maintained

It is critical Connectors are updated in a timely manner and actively maintained so that users of wagmi can rely on them in production settings. The wagmi core team will provide as much assistance as possible to keep Connectors up-to-date with breaking changes from wagmi, but it is your responsibility to ensure that downstream dependencies and issues/discussions related to the Connector are handled in a timely manner. If this is not done, the Connector could be removed from the future versions.

### 4. The Connector should have minimal third-party dependencies

The Connector should rely on as few external libraries or dependencies as possible. This is important for several reasons. First, it helps to ensure the security of the Connector by reducing the potential attack surface (e.g. supply chain attacks). Second, it helps keep the Connector's bundle size down, which can improve initial page-load performance. Finally, having minimal dependencies can improve the reliability of the Connector by reducing the likelihood of conflicts or other issues arising from the use of other external libraries.

### 5. The Connector should use permissive-license dependencies

The Connector should use dependencies with the MIT license (or similar) whenever possible. The MIT license is a permissive open-source license that allows for the use, modification, and distribution of software without many of the restrictions that are common in other open-source licenses. Using dependencies with an MIT license can help to ensure that the Connector can be freely used, modified, and distributed by others without any legal complications.

---

<br>
Expand Down
28 changes: 28 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,31 @@ jobs:
key: modules-${{ hashFiles('pnpm-lock.yaml') }}
- name: Build
run: pnpm build

test:
name: Test
needs: lint
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18]
pnpm-version: [7]
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2.2.4
with:
version: ${{ matrix.pnpm-version }}
- name: Set up Node ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
cache: 'pnpm'
node-version: ${{ matrix.node-version }}
- name: Cache node_modules
uses: actions/cache@v3
with:
path: |
node_modules
packages/**/node_modules
key: modules-${{ hashFiles('pnpm-lock.yaml') }}
- name: Run tests
run: pnpm test
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ The purpose of the references monorepo is so that contributors can open discussi
It consists of:

- **[Chains](/packages/chains/)**: An extensive collection of chains (e.g. mainnet, polygon, bsc, etc) to use in wagmi.
- **Connectors** (Soon): A collection of connectors (e.g. Injected, WalletConnect, etc) to use in wagmi
- **[Connectors](/packages/connectors/)**: A collection of connectors (e.g. Injected, WalletConnect, etc) to use in wagmi

## Contributing

Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@
"build": "pnpm --filter './packages/**' build",
"changeset:release": "pnpm build && changeset publish",
"changeset:version": "changeset version && pnpm install --lockfile-only",
"dev": "pnpm --filter './packages/**' dev",
"lint": "eslint .",
"lint:fix": "pnpm lint --fix",
"lint:format": "prettier --write",
"prepare": "npx simple-git-hooks",
"test": "vitest",
"typecheck": "tsc --noEmit"
},
"devDependencies": {
"@changesets/changelog-github": "^0.4.7",
"@changesets/cli": "^2.25.2",
"@types/eslint": "^8.4.9",
"@types/fs-extra": "^9.0.13",
"@types/node": "^18.11.9",
"@typescript-eslint/eslint-plugin": "^5.42.0",
"@typescript-eslint/parser": "^5.42.0",
Expand All @@ -25,6 +28,8 @@
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-prettier": "^4.2.1",
"execa": "^6.1.0",
"fs-extra": "^11.1.0",
"lint-staged": "^13.0.3",
"prettier": "^2.7.1",
"simple-git-hooks": "^2.8.1",
Expand Down
3 changes: 2 additions & 1 deletion packages/chains/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "tsup"
"build": "tsup",
"dev": "DEV=true tsup"
},
"exports": {
".": {
Expand Down
1 change: 1 addition & 0 deletions packages/chains/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { getConfig } from '../../scripts/tsup'

export default defineConfig(
getConfig({
dev: process.env.DEV === 'true',
entry: ['src/index.ts'],
platform: 'browser',
}),
Expand Down
Empty file removed packages/connectors/.keep
Empty file.
58 changes: 58 additions & 0 deletions packages/connectors/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# `@wagmi/connectors`

Collection of connectors for wagmi.

## Installation

Install the `@wagmi/connectors` package.

```
npm i @wagmi/connectors
```

## Usage

Configure your wagmi client with connectors!

```tsx
import { configureChains, createClient } from 'wagmi'

import { InjectedConnector } from '@wagmi/connectors/injected'
import { CoinbaseWalletConnector } from '@wagmi/connectors/coinbaseWallet'
import { WalletConnectConnector } from '@wagmi/connectors/walletConnect'

const { chains, provider } = configureChains(...)

const client = createClient({
connectors: [
new CoinbaseWalletConnector({
chains,
options: {
appName: 'wagmi',
},
}),
new WalletConnectConnector({
chains,
options: {
qrcode: true,
},
}),
new InjectedConnector({ chains }),
],
provider,
})
```

> If your bundler supports tree-shaking (most likely), only the used connectors will be included in the bundle, so you don't have to worry about bundle size. 😊
## Connectors

- [`InjectedConnector`](/packages/connectors/src/injected.ts)
- [`CoinbaseWalletConnector`](/packages/connectors/src/coinbaseWallet.ts)
- [`MetaMaskConnector`](/packages/connectors/src/metaMask.ts)
- [`MockConnector`](/packages/connectors/src/mock.ts)
- [`WalletConnectConnector`](/packages/connectors/src/walletConnect.ts)

## Contributing

Want to add another chain to the list? Make sure you read the [contributing guide](../../.github/CONTRIBUTING.md) first.
4 changes: 4 additions & 0 deletions packages/connectors/coinbaseWallet/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "module",
"main": "../dist/coinbaseWallet.js"
}
4 changes: 4 additions & 0 deletions packages/connectors/injected/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "module",
"main": "../dist/injected.js"
}
4 changes: 4 additions & 0 deletions packages/connectors/metaMask/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "module",
"main": "../dist/metaMask.js"
}
4 changes: 4 additions & 0 deletions packages/connectors/mock/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "module",
"main": "../dist/mock/index.js"
}
98 changes: 98 additions & 0 deletions packages/connectors/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
{
"name": "@wagmi/connectors",
"description": "A collection of connectors for wagmi",
"license": "MIT",
"version": "0.0.0",
"scripts": {
"build": "tsup",
"dev": "DEV=true tsup"
},
"peerDependencies": {
"@wagmi/core": "0.8.x",
"ethers": "^5.0.0"
},
"peerDependenciesMeta": {
"@wagmi/core": {
"optional": true
}
},
"dependencies": {
"@coinbase/wallet-sdk": "^3.5.4",
"@walletconnect/ethereum-provider": "^1.8.0",
"abitype": "^0.1.8",
"eventemitter3": "^4.0.7"
},
"devDependencies": {
"@wagmi/core": "^0.8.0",
"ethers": "^5.7.2"
},
"type": "module",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"./coinbaseWallet": {
"types": "./dist/coinbaseWallet.d.ts",
"default": "./dist/coinbaseWallet.js"
},
"./injected": {
"types": "./dist/injected.d.ts",
"default": "./dist/injected.js"
},
"./metaMask": {
"types": "./dist/metaMask.d.ts",
"default": "./dist/metaMask.js"
},
"./mock": {
"types": "./dist/mock/index.d.ts",
"default": "./dist/mock/index.js"
},
"./walletConnect": {
"types": "./dist/walletConnect.d.ts",
"default": "./dist/walletConnect.js"
}
},
"files": [
"/coinbaseWallet",
"/dist",
"/injected",
"/metaMask",
"/mock",
"/walletConnect"
],
"sideEffects": false,
"contributors": [
"awkweb.eth <t@wagmi.sh>",
"jxom.eth <j@wagmi.sh>"
],
"homepage": "https://wagmi.sh",
"ethereum": "wagmi-dev.eth",
"funding": [
{
"type": "gitcoin",
"url": "https://gitcoin.co/grants/4493/wagmi-react-hooks-library-for-ethereum"
},
{
"type": "github",
"url": "https://github.com/sponsors/wagmi-dev"
}
],
"repository": {
"type": "git",
"url": "https://github.com/wagmi-dev/references.git",
"directory": "packages/connectors"
},
"keywords": [
"react",
"hooks",
"eth",
"ethereum",
"dapps",
"wallet",
"web3",
"abi"
]
}
Loading

0 comments on commit 55a0ca2

Please sign in to comment.