Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: prepare for the first release #18

Merged
merged 4 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 8 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ web3.registerPlugin(new WalletRpcPlugin());

### Methods

#### addEthereumChain
Click on the method name for detailed documentation.

#### [addEthereumChain](https://web3.github.io/web3-wallet-rpc-utils/classes/WalletRpcPlugin.html#addEthereumChain)

Invokes the `wallet_addEthereumChain` method as defined in [EIP-3085](https://eips.ethereum.org/EIPS/eip-3085#wallet_addethereumchain).

Expand All @@ -65,15 +67,15 @@ await web3.walletRpc.addEthereumChain({
});
```

#### switchEthereumChain
#### [switchEthereumChain](https://web3.github.io/web3-wallet-rpc-utils/classes/WalletRpcPlugin.html#switchEthereumChain)

Invokes the `wallet_switchEthereumChain` method as defined in [EIP-3326](https://eips.ethereum.org/EIPS/eip-3326#wallet_switchethereumchain).

```typescript
await web3.walletRpc.switchEthereumChain(5000);
```

#### watchAsset
#### [watchAsset](https://web3.github.io/web3-wallet-rpc-utils/classes/WalletRpcPlugin.html#watchAsset)

Invokes the `wallet_watchAsset` method as defined in [EIP-747](https://eips.ethereum.org/EIPS/eip-747#specification).

Expand All @@ -87,7 +89,7 @@ await web3.walletRpc.watchAsset({
});
```

#### requestPermissions
#### [requestPermissions](https://web3.github.io/web3-wallet-rpc-utils/classes/WalletRpcPlugin.html#requestPermissions)

Invokes the `wallet_requestPermissions` method as defined in [EIP-2255](https://eips.ethereum.org/EIPS/eip-2255#specification).

Expand All @@ -97,15 +99,15 @@ const permissions = await web3.walletRpc.requestPermissions({
});
```

#### getPermissions
#### [getPermissions](https://web3.github.io/web3-wallet-rpc-utils/classes/WalletRpcPlugin.html#getPermissions)

Invokes the `wallet_getPermissions` method as defined in [EIP-2255](https://eips.ethereum.org/EIPS/eip-2255#specification).

```typescript
const permissions = await web3.walletRpc.getPermissions();
```

#### revokePermissions
#### [revokePermissions](https://web3.github.io/web3-wallet-rpc-utils/classes/WalletRpcPlugin.html#revokePermissions)

Invokes the `wallet_revokePermissions` method as defined in [MetaMask docs](https://docs.metamask.io/wallet/reference/json-rpc-methods/wallet_revokepermissions/).

Expand All @@ -115,36 +117,6 @@ const permissions = await web3.walletRpc.revokePermissions({
});
```

### Experimental methods

#### updateEthereumChain

Invokes the `wallet_updateEthereumChain` method as defined in [EIP-2015](https://eips.ethereum.org/EIPS/eip-2015).

```typescript
await web3.walletRpc.updateEthereumChain({
chainId: 5000,
blockExplorerUrls: ['https://mantlescan.xyz'],
chainName: 'Mantle',
nativeCurrency: {
name: 'Mantle',
symbol: 'MNT',
decimals: 18,
},
rpcUrls: ['https://rpc.mantle.xyz'],
});
```

#### getOwnedAssets

Invokes the `wallet_getOwnedAssets` method as defined in [EIP-2256](https://eips.ethereum.org/EIPS/eip-2256).

```typescript
const ownedAssets = await web3.walletRpc.getOwnedAssets({
address: '0xa5653e88D9c352387deDdC79bcf99f0ada62e9c6',
});
```

## Contributing

We welcome pull requests! For major changes, please open an issue first to discuss the proposed modifications.
Expand Down
57 changes: 14 additions & 43 deletions WALLET_SUPPORT.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

## Browser extension wallets

| Method | Metamask | Coinbase Wallet | Trust Wallet | Enkrypt | Rainbow | Rabby Wallet | Exodus | Phantom |
| -------------------------- | -------- | --------------- | ------------ | ------- | ------- | ------------ | ------ | ------- |
| wallet_addEthereumChain | ✓ | ✓ (\*) | ✓ | ✓ | ✓ (\*) | ✓ | x (\*) | x (\*) |
| wallet_switchEthereumChain | ✓ | ✓ (\*) | ✓ | ✓ | ✓ | ✓ | ✓ (\*) | ✓ (\*) |
| wallet_watchAsset | ✓ (\*) | ✓ | ✓ (\*) | x | ✓ (\*) | ✓ (\*) | x | ✓ (\*) |
| wallet_requestPermissions | ✓ (\*) | x | ✓ | x (\*) | x | ✓ | ✓ | ✓ |
| wallet_getPermissions | ✓ | x | ✓ | x | x | ✓ | ✓ | ✓ |
| wallet_revokePermissions | ✓ | x | ✓ | x | x | ✓ | ✓ (\*) | x |
| Method | Metamask | Coinbase Wallet | Trust Wallet | Enkrypt | Rainbow | Rabby Wallet | Exodus | Phantom | Uniswap Extension |
| -------------------------- | -------- | --------------- | ------------ | ------- | ------- | ------------ | ------ | ------- | ----------------- |
| wallet_addEthereumChain | ✓ | ✓ (\*) | ✓ | ✓ | ✓ (\*) | ✓ | x (\*) | x (\*) | x |
| wallet_switchEthereumChain | ✓ | ✓ (\*) | ✓ | ✓ | ✓ | ✓ | ✓ (\*) | ✓ (\*) | ✓ (\*) |
| wallet_watchAsset | ✓ | ✓ | ✓ (\*) | | ✓ | ✓ | x (\*) | x | x |
| wallet_requestPermissions | ✓ (\*) | x | ✓ | x (\*) | x | ✓ | ✓ | ✓ | ✓ |
| wallet_getPermissions | ✓ | x | ✓ | x | x | ✓ | ✓ | ✓ | ✓ |
| wallet_revokePermissions | ✓ | x | ✓ | x | x | ✓ | ✓ (\*) | x | ✓ |

- (✓) Supported
- (x) Not supported
Expand All @@ -29,14 +29,6 @@
#### Metamask

- `wallet_requestPermissions` and `wallet_getPermissions`: Returns a full response containing all permission fields according to the specification.
- `wallet_watchAsset`: There’s an issue with Web3RequestManager, causing an error with the wallet's response:

```
ResponseError: Returned error: Cannot destructure property 'tokenId' of 'n' as it is undefined.
at Web3RequestManager.<anonymous> (web3_request_manager.ts:178:1)
at Generator.next (<anonymous>)
at fulfilled (web3_request_manager.ts:1:1)`
```

#### Coinbase Wallet

Expand All @@ -46,21 +38,7 @@ at fulfilled (web3_request_manager.ts:1:1)`
### Trust Wallet

- General Behavior is very similarly to MetaMask.
- `wallet_watchAsset`: Produces an error due to an issue with destructuring the wallet’s response:

```
WatchAsset.tsx:45 TypeError: Cannot destructure property 'address' of 'A' as it is undefined.
at wi.request (inpage.js:247:201226)
at inpage.js:247:206755
at yu.handleStaticRequests (inpage.js:247:207086)
at yu.request (inpage.js:247:206709)
at web3_request_manager.ts:271:1
at new Promise (<anonymous>)
at Web3RequestManager.<anonymous> (web3_request_manager.ts:250:1)
at Generator.next (<anonymous>)
at web3_request_manager.ts:1:1
at new Promise (<anonymous>)
```
- `wallet_watchAsset`: Requires `symbol` and `decimals` fields, which are optional according to the specification and in other wallets.

### Enkrypt

Expand All @@ -69,32 +47,25 @@ WatchAsset.tsx:45 TypeError: Cannot destructure property 'address' of 'A' as it
### Rainbow

- `wallet_addEthereumChain`: Adds a chain but does not switch to it; fails if the network is already known to the wallet.
- `wallet_watchAsset`: Fails with the error `"Internal error: Cannot read properties of undefined (reading 'address')"`.

### Rabby Wallet

- `wallet_requestPermissions` and `wallet_getPermissions`: Returns a response object containing only `parentCapability`, but functions as expected.
- `wallet_watchAsset`: Opens a modal with an “Add Custom Token” header, but it remains stuck and does not complete the action.

### Exodus

- `wallet_addEthereumChain` and `wallet_switchEthereumChain`: Only work with chains natively supported by the wallet; new chains cannot be added.
- `wallet_watchAsset`: The promise resolves successfully with a value of `true`, but no asset is actually added.
- `wallet_requestPermissions` and `wallet_getPermissions`: Returns a response object containing only `parentCapability`, but functions as expected.
- `wallet_revokePermissions`: Revokes permissions but also triggers an error: `DisconnectedError: The provider is disconnected from all chains`. This appears to be an issue with the wallet itself.

### Phantom

- `wallet_addEthereumChain` and `wallet_switchEthereumChain`: Only work with chains natively supported by the wallet; new chains cannot be added.
- `wallet_watchAsset`: Fails with an error:

```
WatchAsset.tsx:45 Ir: Missing or invalid parameters.
at r.request (chrome-extension://bfnaelmomeimhlpmgjnjophhpkkoljpa/evmAsk.js:7:5094)
at Web3RequestManager.<anonymous> (http://localhost:3000/static/js/bundle.js:80237:25)
at Generator.next (<anonymous>)
at http://localhost:3000/static/js/bundle.js:80100:67
at new Promise (<anonymous>)
```

### Uniswap Extension

- `wallet_switchEthereumChain`: Only works with chains natively supported by the wallet; new chains cannot be added.

## Mobile wallets using WalletConnect

Expand Down
17 changes: 11 additions & 6 deletions packages/example-react-app/src/wallet-components/WatchAsset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ const tokens: Record<string, WatchAssetRequest> = {
type: 'ERC20',
options: {
address: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
symbol: 'USDC',
},
},
usdc_full: {
type: 'ERC20',
options: {
address: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
symbol: 'USDC', // This is required by some wallets, while optional for others and in the spec
decimals: 18, // This is required by some wallets, while optional for others and in the spec
},
},
scroll: {
Expand All @@ -35,10 +42,7 @@ function WatchAssetButton({
.watchAsset(asset)
.then((response) => {
// eslint-disable-next-line no-console
console.log(
`Successfully added ${asset.options.symbol ?? ''} with response`,
response,
);
console.log('Successfully resolved watchAsset request with response', response);
})
.catch((e) => {
// eslint-disable-next-line no-console
Expand All @@ -64,7 +68,8 @@ export function WatchAsset() {
return (
<div>
<h4>Add token to wallet&apos;s list</h4>
<WatchAssetButton asset={tokens.usdc} />
<WatchAssetButton asset={tokens.usdc} description="USDC (Only address)" />
<WatchAssetButton asset={tokens.usdc_full} description="(Full spec)" />
<WatchAssetButton asset={tokens.scroll} description="(Only on Scroll Network)" />
</div>
);
Expand Down
19 changes: 13 additions & 6 deletions packages/web3-plugin-wallet-rpc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ web3.registerPlugin(new WalletRpcPlugin());

### Methods

#### addEthereumChain
Click on the method name for detailed documentation.

#### [addEthereumChain](https://web3.github.io/web3-wallet-rpc-utils/classes/WalletRpcPlugin.html#addEthereumChain)

Invokes the `wallet_addEthereumChain` method as defined in [EIP-3085](https://eips.ethereum.org/EIPS/eip-3085#wallet_addethereumchain).

Expand All @@ -58,15 +60,15 @@ await web3.walletRpc.addEthereumChain({
});
```

#### switchEthereumChain
#### [switchEthereumChain](https://web3.github.io/web3-wallet-rpc-utils/classes/WalletRpcPlugin.html#switchEthereumChain)

Invokes the `wallet_switchEthereumChain` method as defined in [EIP-3326](https://eips.ethereum.org/EIPS/eip-3326#wallet_switchethereumchain).

```typescript
await web3.walletRpc.switchEthereumChain(5000);
```

#### watchAsset
#### [watchAsset](https://web3.github.io/web3-wallet-rpc-utils/classes/WalletRpcPlugin.html#watchAsset)

Invokes the `wallet_watchAsset` method as defined in [EIP-747](https://eips.ethereum.org/EIPS/eip-747#specification).

Expand All @@ -80,7 +82,7 @@ await web3.walletRpc.watchAsset({
});
```

#### requestPermissions
#### [requestPermissions](https://web3.github.io/web3-wallet-rpc-utils/classes/WalletRpcPlugin.html#requestPermissions)

Invokes the `wallet_requestPermissions` method as defined in [EIP-2255](https://eips.ethereum.org/EIPS/eip-2255#specification).

Expand All @@ -90,15 +92,15 @@ const permissions = await web3.walletRpc.requestPermissions({
});
```

#### getPermissions
#### [getPermissions](https://web3.github.io/web3-wallet-rpc-utils/classes/WalletRpcPlugin.html#getPermissions)

Invokes the `wallet_getPermissions` method as defined in [EIP-2255](https://eips.ethereum.org/EIPS/eip-2255#specification).

```typescript
const permissions = await web3.walletRpc.getPermissions();
```

#### revokePermissions
#### [revokePermissions](https://web3.github.io/web3-wallet-rpc-utils/classes/WalletRpcPlugin.html#revokePermissions)

Invokes the `wallet_revokePermissions` method as defined in [MetaMask docs](https://docs.metamask.io/wallet/reference/json-rpc-methods/wallet_revokepermissions/).

Expand All @@ -108,6 +110,11 @@ const permissions = await web3.walletRpc.revokePermissions({
});
```

## Contributing

We welcome pull requests! For major changes, please [open an issue](https://github.com/web3/web3-wallet-rpc-utils) first to discuss the proposed modifications.
Also, ensure that you update tests as needed to reflect the changes.

## License

[MIT](https://choosealicense.com/licenses/mit/)
3 changes: 1 addition & 2 deletions packages/web3-plugin-wallet-rpc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@
"typescript": "5.3.x",
"web3-core": "^4.7.0",
"web3-types": "^1.8.1",
"web3-utils": "^4.3.2",
"web3-validator": "^2.0.6"
"web3-utils": "^4.3.2"
},
"peerDependencies": {
"web3": ">= 4.14.0"
Expand Down
Loading
Loading