generated from web3/web3.js-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Workspace README as API Docs Index
- Loading branch information
Showing
2 changed files
with
2 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,113 +1,3 @@ | ||
# Web3.js Plugin for Wallet RPC methods | ||
|
||
This Web3.js plugin adds support for the following wallet-related RPC methods: | ||
|
||
- [wallet_addEthereumChain (EIP-3085)](https://eips.ethereum.org/EIPS/eip-3085) | ||
- [wallet_switchEthereumChain (EIP-3326)](https://eips.ethereum.org/EIPS/eip-3326) | ||
- [wallet_watchAsset (EIP-747)](https://eips.ethereum.org/EIPS/eip-747) | ||
- [wallet_requestPermissions (EIP-2255)](https://eips.ethereum.org/EIPS/eip-2255) | ||
- [wallet_getPermissions (EIP-2255)](https://eips.ethereum.org/EIPS/eip-2255) | ||
- [wallet_revokePermissions](https://docs.metamask.io/wallet/reference/json-rpc-methods/wallet_revokepermissions/) | ||
|
||
## Installation | ||
|
||
Use your preferred package manager. Ensure that `web3` is also installed and integrated into your project. | ||
|
||
```bash | ||
npm install web3-plugin-wallet-rpc | ||
``` | ||
|
||
```bash | ||
yarn add web3-plugin-wallet-rpc | ||
``` | ||
|
||
```bash | ||
pnpm add web3-plugin-wallet-rpc | ||
``` | ||
|
||
## Usage | ||
|
||
### Register plugin | ||
|
||
```typescript | ||
import { Web3 } from 'web3'; | ||
import { WalletRpcPlugin } from 'web3-plugin-wallet-rpc'; | ||
|
||
const web3 = new Web3('https://eth.llamarpc.com'); | ||
web3.registerPlugin(new WalletRpcPlugin()); | ||
``` | ||
|
||
### Methods | ||
|
||
#### addEthereumChain | ||
|
||
Invokes the `wallet_addEthereumChain` method as defined in [EIP-3085](https://eips.ethereum.org/EIPS/eip-3085#wallet_addethereumchain). | ||
|
||
```typescript | ||
await web3.walletRpc.addEthereumChain({ | ||
chainId: 5000, | ||
blockExplorerUrls: ['https://mantlescan.xyz'], | ||
chainName: 'Mantle', | ||
iconUrls: ['https://icons.llamao.fi/icons/chains/rsz_mantle.jpg'], | ||
nativeCurrency: { | ||
name: 'Mantle', | ||
symbol: 'MNT', | ||
decimals: 18, | ||
}, | ||
rpcUrls: ['https://rpc.mantle.xyz'], | ||
}); | ||
``` | ||
|
||
#### 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 | ||
|
||
Invokes the `wallet_watchAsset` method as defined in [EIP-747](https://eips.ethereum.org/EIPS/eip-747#specification). | ||
|
||
```typescript | ||
await web3.walletRpc.watchAsset({ | ||
type: 'ERC20', | ||
options: { | ||
address: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', | ||
symbol: 'USDC', | ||
}, | ||
}); | ||
``` | ||
|
||
#### requestPermissions | ||
|
||
Invokes the `wallet_requestPermissions` method as defined in [EIP-2255](https://eips.ethereum.org/EIPS/eip-2255#specification). | ||
|
||
```typescript | ||
const permissions = await web3.walletRpc.requestPermissions({ | ||
eth_accounts: {}, | ||
}); | ||
``` | ||
|
||
#### 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 | ||
|
||
Invokes the `wallet_revokePermissions` method as defined in [MetaMask docs](https://docs.metamask.io/wallet/reference/json-rpc-methods/wallet_revokepermissions/). | ||
|
||
```typescript | ||
const permissions = await web3.walletRpc.revokePermissions({ | ||
eth_accounts: {}, | ||
}); | ||
``` | ||
|
||
## License | ||
|
||
[MIT](https://choosealicense.com/licenses/mit/) | ||
Refer to the [README](../../README.md) file located in the root of this repository. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters