diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml
index 8bb95cb..cf2b9ad 100644
--- a/.github/FUNDING.yml
+++ b/.github/FUNDING.yml
@@ -1 +1 @@
-custom: ['https://arbiscan.io/address/0x9D75F4EbcB8e7669E59dcc27CBadC698E0F77187#internaltx']
+custom: ['https://arbiscan.io/address/0x9D75F4EbcB8e7669E59dcc27CBadC698E0F77187#internaltx', 'https://explorer.gitcoin.co/#/round/424/0xd4cc0dd193c7dc1d665ae244ce12d7fab337a008/0xd4cc0dd193c7dc1d665ae244ce12d7fab337a008-75']
diff --git a/README.md b/README.md
index 8db52d1..41a9a1b 100644
--- a/README.md
+++ b/README.md
@@ -26,153 +26,55 @@
-## Documentation
+# Vue Dapp
-- v1: Work in progress, see [Discussion#141](https://github.com/vu3th/vue-dapp/discussions/141)
-
-
-Brief versions and functionalities are as follows:
-
-- v0.12.x: Add bitget wallet
-- v0.11.x: Uses ethers v5 with WalletConnect dependencies update.
-- v0.10.x: Uses ethers v6 and supports WalletConnect v2.
-- v0.9.x: Uses ethers v5 and supports WalletConnect v2.
-- Before v0.8.x: Uses ethers v5 and does not support WalletConnect v2.
+Vue Dapp v1 is working in progress, see [Discussion#141](https://github.com/vu3th/vue-dapp/discussions/141). I would probably release a stable version by the end of 2023.
I recommend keeping an eye on [vue3-dapp-starter](https://github.com/vu3th/vue3-dapp-starter) and [nuxt-dapp](https://github.com/vu3th/nuxt-dapp), as it strives to maintain a development-friendly version whenever possible.
-Please be cautious when using the documentation below, as it has not been updated for some time.
-- [Documentation (v0.9.x)](https://vue-dapp-docs.netlify.app/)
-- [Migrating to v0.5.x ~ v0.9.x](https://vue-dapp-docs.netlify.app/migration)
+## Monorepo Architecture
-## Packages
+library
-| Package | Description |
+| Name | Description |
| ----------------------- | ------------------------------------------------- |
| @vue-dapp/core | useWalletStore, connector, utils, and metamask... |
| @vue-dapp/vd-board | Vue components for connecting wallet |
| @vue-dapp/walletconnect | WalletConnect integration |
-| @vue-dapp/legacy | vue-dapp version below v1 |
-| @vue-dapp/docs | documentation |
-| @vue-dapp/app | Nuxt 3 demo for v1 |
-| @vue-dapp/demo | Vue 3 demo for @vue-dapp/legacy |
+app
-## Installation (below v0.10.x)
+| Name | Description |
+| -------------- | ------------------ |
+| @vue-dapp/app | Nuxt 3 demo for v1 |
+| @vue-dapp/docs | documentation |
-```bash
-yarn add ethers vue-dapp
-```
+legacy
-If you want to support more wallet providers not only MetaMask, you should install respective packages to enable the dynamic import.
+| Name | Description |
+| ---------------- | ----------------------------- |
+| @vue-dapp/legacy | vue-dapp version below v1 |
+| @vue-dapp/demo | Vue demo for @vue-dapp/legacy |
-- Support WalletConnect
-```bash
-yarn add @walletconnect/web3-provider
-```
-- Support Coinbase Wallet
-```bash
-yarn add @coinbase/wallet-sdk
-```
+## Installation
-- Support Gnosis Safe
```bash
-yarn add @gnosis.pm/safe-apps-provider @gnosis.pm/safe-apps-sdk
+yarn add @vue-dapp/core @vue-dapp/vd-board
```
-## Quick Start
-
-Step 1. Add plugin to your app:
-
-```javascript
-import { VueDapp } from "vue-dapp";
-const app = createApp(App);
-app.use(VueDapp);
-app.mount("#app");
-```
+If you want to support more wallet providers not only MetaMask, you should install respective packages.
-Step 2. By default, VueDapp includes `Mainnet` and `Goerli` networks, but you can extend it to include other networks:
-
-```javascript
-app.use(VueDapp, {
- autoConnect: true, // Automatically connect MetaMask wallet when the page is loaded
- networks: {
- 80001: {
- chainId: ethers.utils.hexValue(80001),
- blockExplorerUrls: ['https://mumbai.polygonscan.com/'],
- chainName: 'Mumbai',
- rpcUrls: ['https://rpc-mumbai.maticvigil.com/'],
- nativeCurrency: {
- name: 'Mumbai',
- decimals: 18,
- symbol: 'MATIC',
- },
- },
- 42161: {
- ...
- },
- },
-});
-
-```
-For more examples please check:
-https://github.com/wagmi-dev/wagmi/blob/main/packages/core/src/constants/chains.ts
-
-
-Step 3. Add `` to your `App.vue` and add a button to open the board:
-
-```vue
-
-
-```
-
-Step 4. Construct your connectors and use composable functions in your scripts:
-
-```js
-import {
- MetaMaskConnector,
- WalletConnectConnector,
- CoinbaseWalletConnector,
- useBoard,
-} from "vue-dapp";
-
-setup() {
- const { open } = useBoard();
- const infuraId = "";
- const connectors = [
- new MetaMaskConnector({
- appUrl: "http://localhost:3000",
- }),
- new WalletConnectConnector({
- qrcode: true,
- rpc: {
- 1: `https://mainnet.infura.io/v3/${infuraId}`,
- 4: `https://rinkeby.infura.io/v3/${infuraId}`,
- },
- }),
- new CoinbaseWalletConnector({
- appName: "Vue Dapp",
- jsonRpcUrl: `https://mainnet.infura.io/v3/${infuraId}`,
- }),
- ];
- return {
- connectors,
- open,
- };
-}
+### WalletConnect
+```bash
+yarn add @vue-dapp/walletconnect
```
-Take a look at [Configurations](https://vue-dapp-docs.netlify.app/configurations) for more informations about Vue CLI, Vite, and Nuxt3 configurations.
-
-To see the demo code, check it out [here](https://github.com/vu3th/vue-dapp/blob/main/demo/src/App.vue).
-
## Support 🙏
-Gitcoin Grants 18: https://explorer.gitcoin.co/#/round/10/0x8de918f0163b2021839a8d84954dd7e8e151326d/0x8de918f0163b2021839a8d84954dd7e8e151326d-43
+Gitcoin Grants 19: https://explorer.gitcoin.co/#/round/424/0xd4cc0dd193c7dc1d665ae244ce12d7fab337a008/0xd4cc0dd193c7dc1d665ae244ce12d7fab337a008-75
## MIT license
Copyright (c) 2021-present, Johnson Chen ([@chnejohnson](https://twitter.com/chnejohnson))
-
diff --git a/app/components/Web3Provider.vue b/app/components/Web3Provider.vue
index a1c35b4..07d63f6 100644
--- a/app/components/Web3Provider.vue
+++ b/app/components/Web3Provider.vue
@@ -6,37 +6,42 @@ import { ethers } from 'ethers'
import { MetaMaskConnector, useWalletStore } from '@vue-dapp/core'
import { WalletConnectConnector } from '@vue-dapp/walletconnect'
import { Board } from '@vue-dapp/vd-board'
+import '@vue-dapp/vd-board/dist/style.css'
const dappStore = useDappStore()
const { isConnected, user } = storeToRefs(dappStore)
-const { onActivated, onChanged, onDeactivated } = useWalletStore()
+const { onActivated, onChanged, onDeactivated, setDumb } = useWalletStore()
+setDumb(false)
-onActivated(async ({ address, provider }) => {
+onActivated(async ({ address, provider, chainId }) => {
+ console.log('onActivated')
const ethersProvider = new ethers.BrowserProvider(provider)
const signer = await ethersProvider.getSigner()
- const network = await ethersProvider.getNetwork()
dappStore.setUser({
address,
signer,
- chainId: Number(network.chainId),
+ chainId,
})
})
-onChanged(async ({ address, provider }) => {
+onChanged(async ({ address, provider, chainId }) => {
+ console.log('onChanged')
+
const ethersProvider = new ethers.BrowserProvider(provider)
const signer = await ethersProvider.getSigner()
- const network = await ethersProvider.getNetwork()
dappStore.setUser({
address,
signer,
- chainId: Number(network.chainId),
+ chainId,
})
})
onDeactivated(() => {
+ console.log('onDeactivated')
+
dappStore.resetUser()
})
@@ -93,6 +98,7 @@ watch(isConnected, () => {
diff --git a/app/components/wallet/UserStatus.vue b/app/components/wallet/UserStatus.vue
index e0e055c..89e5c3c 100644
--- a/app/components/wallet/UserStatus.vue
+++ b/app/components/wallet/UserStatus.vue
@@ -8,7 +8,7 @@ import { useBoardStore } from '@vue-dapp/vd-board'
const { open } = useBoardStore()
const { disconnect } = useWalletStore()
-const { connector, status, address, isConnected } = storeToRefs(useWalletStore())
+const { connector, status, address, isConnected, dumb } = storeToRefs(useWalletStore())
const dappStore = useDappStore()
const { isNetworkUnmatched } = storeToRefs(dappStore)
diff --git a/app/nuxt.config.ts b/app/nuxt.config.ts
index 30bdc58..0a7bbf3 100644
--- a/app/nuxt.config.ts
+++ b/app/nuxt.config.ts
@@ -1,5 +1,3 @@
-import { nodePolyfills } from 'vite-plugin-node-polyfills'
-
// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
devtools: { enabled: true },
@@ -59,7 +57,4 @@ export default defineNuxtConfig({
],
},
},
- vite: {
- plugins: [nodePolyfills()],
- },
})
diff --git a/app/package.json b/app/package.json
index 840fe24..26ef1ea 100644
--- a/app/package.json
+++ b/app/package.json
@@ -17,8 +17,6 @@
"@vue-dapp/walletconnect": "workspace:^",
"@vueuse/core": "^10.5.0",
"@vueuse/nuxt": "^10.5.0",
- "@walletconnect/ethereum-provider": "^2.10.2",
- "@walletconnect/modal": "^2.6.2",
"copy-to-clipboard": "^3.3.3",
"ethers": "6.8.0",
"nuxt-icon": "^0.5.0",
@@ -36,7 +34,6 @@
"postcss": "^8.4.20",
"postcss-custom-properties": "^13.3.2",
"sass": "^1.69.3",
- "vite-plugin-node-polyfills": "^0.15.0",
"vue": "^3.3.4",
"vue-router": "^4.2.5"
}
diff --git a/docs/.vitepress/config.js b/docs/.vitepress/config.js
index 79b086c..600603d 100644
--- a/docs/.vitepress/config.js
+++ b/docs/.vitepress/config.js
@@ -18,12 +18,12 @@ module.exports = {
repo: 'chnejohnson/vue-dapp',
nav: [
{
- text: 'v0.7.1',
+ text: 'v1.0.0-alpha',
link: 'https://github.com/vu3th/vue-dapp/releases',
},
{
text: 'Demo',
- link: 'https://vuedapp.vercel.app/',
+ link: 'https://vue-dapp.vercel.app/',
},
],
sidebar: [
@@ -34,66 +34,26 @@ module.exports = {
text: 'Getting Started',
link: '/',
},
+ // {
+ // text: 'Migrating to v1',
+ // link: '/migration',
+ // },
{
- text: 'Migrating to v0.5.x',
- link: '/migration',
- },
- {
- text: 'Configurations',
- link: '/configurations',
+ text: 'Examples',
+ link: '/examples',
},
{
text: 'Contributing',
link: '/contributing',
},
- {
- text: 'Resources',
- link: '/resources',
- },
],
},
{
text: 'API',
items: [
{
- text: 'Plugin Options',
- link: '/api/plugin-options',
- },
- {
- text: 'Components',
- link: '/api/components',
- },
- {
- text: 'Connectors',
- link: '/api/connectors',
- },
- {
- text: 'Constants',
- link: '/api/constants',
- },
- {
- text: 'Directives',
- link: '/api/directives',
- },
- {
- text: 'useWallet',
- link: '/api/use-wallet',
- },
- {
- text: 'useEthers',
- link: '/api/use-ethers',
- },
- {
- text: 'useEthersHooks',
- link: '/api/use-ethers-hooks',
- },
- {
- text: 'useMulticall',
- link: '/api/use-multicall',
- },
- {
- text: 'Utilities',
- link: '/api/utilities',
+ text: '@vue-dapp/vd-board',
+ link: '/api/vd-board.md',
},
],
},
diff --git a/docs/api/components.md b/docs/api/components.md
deleted file mode 100644
index a869212..0000000
--- a/docs/api/components.md
+++ /dev/null
@@ -1,28 +0,0 @@
-# Components
-
-- `` - for wallet board.
-- `` - for a simple modal.
-
-[source code](https://github.com/vu3th/vue-dapp/tree/main/src/components)
-
-## vd-board
-
-### Usage
-```vue
-
-
- loading...
-
-
-```
-
-### Props
-
-- `dark`: boolean, defaults: false - When set to true, the board will be set to dark mode.
-- `connectors`: Connectors[], defaults: [] - An array of [Connectors](/api/connectors.html) that defines the wallet options on board.
-- `autoConnectErrorHandler`: Function, default: () => void - catch error when a auto-connect error occurs.
-- `connectErrorHandler`: Function, default: () => void - catch error when a connect error occurs.
-### Slots
-
-- `connecting` - Provide a custom content when connecting wallet.
-- `loading` - Provide a custom content when loading data.
diff --git a/docs/api/connectors.md b/docs/api/connectors.md
deleted file mode 100644
index f9b9193..0000000
--- a/docs/api/connectors.md
+++ /dev/null
@@ -1,245 +0,0 @@
-# Connectors
-
-[source code](https://github.com/vu3th/vue-dapp/tree/main/src/connectors)
-
-## Connector Interface
-
-```ts
-declare abstract class Connector {
- abstract readonly name: string;
- readonly options: Options;
- constructor(options: Options);
- abstract connect(): Promise>;
- abstract getProvider(): Promise;
- abstract disconnect(): Promise;
- abstract onDisconnect(handler: (...args: any[]) => any): void;
- abstract onAccountsChanged(handler: (accounts: string[]) => any): void;
- abstract onChainChanged(handler: (chainId: number) => any): void;
- switchChain?(chainId: number): Promise;
-}
-declare type ConnectorData = {
- account: string;
- provider: Provider;
-};
-```
-
-## MetaMaskConnector
-
-The MetaMaskConnector supports connecting with MetaMask.
-* Docs: https://docs.metamask.io/guide/ethereum-provider.html
-* JSON RPC API: https://metamask.github.io/api-playground/api-documentation
-
-### Usage
-```ts
-const connector = new MetaMaskConnector({
- appUrl: 'http://localhost:3000',
-}),
-```
-
-### Configuration
-- `appUrl` (optional): Add deep link to MetaMask wallet on mobile device, see https://github.com/vu3th/vue-dapp/pull/29
-
-
-### Types
-```ts
-/**
- * MetaMask
- * Docs: https://docs.metamask.io/guide/ethereum-provider.html
- * JSON RPC API: https://metamask.github.io/api-playground/api-documentation
- */
-interface MetaMaskProvider extends MetaMaskEthereumProvider {
- isMetaMask: boolean;
- providers?: MetaMaskProvider[];
- isConnected: () => boolean;
- request: (request: {
- method: string;
- params?: any[] | undefined;
- }) => Promise;
- selectedAddress: string;
-}
-/**
- * source: @metamask/detect-provider
- * https://github.com/MetaMask/detect-provider/blob/main/src/index.ts
- */
-interface MetaMaskEthereumProvider {
- isMetaMask?: boolean;
- once(eventName: string | symbol, listener: (...args: any[]) => void): this;
- on(eventName: string | symbol, listener: (...args: any[]) => void): this;
- off(eventName: string | symbol, listener: (...args: any[]) => void): this;
- addListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
- removeListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
- removeAllListeners(event?: string | symbol): this;
-}
-interface Window {
- ethereum?: MetaMaskProvider;
-}
-declare type MetaMaskConnectorOptions = {
- appUrl?: string;
-};
-declare class MetaMaskConnector extends Connector {
- #private;
- readonly name = "metaMask";
- constructor(options?: MetaMaskConnectorOptions);
- static checkConnection(): Promise;
- connect(): Promise<{
- account: any;
- provider: MetaMaskProvider;
- }>;
- getProvider(): Promise;
- /**
- * MetaMask do not support programmatic disconnect.
- * @see https://github.com/MetaMask/metamask-extension/issues/10353
- */
- disconnect(): Promise;
- /**
- * @note MetaMask disconnect event would be triggered when the specific chain changed (like L2 network),
- * and will not be triggered when a user clicked disconnect in wallet...
- */
- onDisconnect(handler: (error: ProviderRpcError) => void): void;
- onAccountsChanged(handler: (accounts: string[]) => void): void;
- onChainChanged(handler: (chainId: number) => void): void;
- switchChain(chainId: number): Promise;
- addChain(networkDetails: AddEthereumChainParameter): Promise;
-}
-interface AddEthereumChainParameter {
- chainId: string;
- chainName: string;
- nativeCurrency: {
- name?: string;
- symbol: string;
- decimals: number;
- };
- rpcUrls: string[];
- blockExplorerUrls?: string[];
- iconUrls?: string[];
-}
-```
-## WalletConnectConnector
-The WalletConnectConnector supports connecting with WalletConnect.
-
-For more details, see WalletConnect v1.0 docs
-* Docs: https://docs.walletconnect.com/quick-start/dapps/web3-provider
-* Test Wallet: https://test.walletconnect.org/
-* Source: https://github.com/WalletConnect/walletconnect-monorepo/blob/v1.0/packages/providers/web3-provider/src/index.ts
-
-### Usage
-```ts
-const connector = new WalletConnectConnector({
- qrcode: true,
- rpc: {
- 1: `https://mainnet.infura.io/v3/${infuraId}`,
- 4: `https://rinkeby.infura.io/v3/${infuraId}`,
- },
-})
-```
-
-### Types
-```ts
-/**
- * WalletConnect v1.0 \
- * Docs: https://docs.walletconnect.com/quick-start/dapps/web3-provider \
- * Test Wallet: https://test.walletconnect.org/ \
- * Source: https://github.com/WalletConnect/walletconnect-monorepo/blob/v1.0/packages/providers/web3-provider/src/index.ts
- */
-interface IWalletConnectProvider extends WalletConnectProvider {
-}
-declare type WalletConnectOptions = ConstructorParameters[0];
-declare class WalletConnectConnector extends Connector {
- #private;
- readonly name = "walletConnect";
- constructor(options: WalletConnectOptions);
- connect(): Promise<{
- account: string;
- provider: WalletConnectProvider;
- }>;
- getProvider(): Promise;
- disconnect(): Promise;
- onDisconnect(handler: (code: number, reason: string) => void): void;
- onAccountsChanged(handler: (accounts: string[]) => void): void;
- onChainChanged(handler: (chainId: number) => void): void;
- /**
- * @error Not support for WalletConnect v1.0
- */
- switchChain(chainId: number): Promise;
-}
-```
-
-
-## Coinbase Wallet
-The CoinbaseWalletConnector supports connecting with Coinbase Wallet using the [Coinbase Wallet SDK](https://docs.cloud.coinbase.com/wallet-sdk/docs/)
-
-### Usage
-```ts
-const connector = new CoinbaseWalletConnector({
- appName: 'Vue Dapp',
- jsonRpcUrl: `https://mainnet.infura.io/v3/${infuraId}`,
-})
-```
-
-### Types
-```ts
-/**
- * Coinbase Wallet SDK
- * Docs: https://docs.cloud.coinbase.com/wallet-sdk/docs/
- */
-interface ICoinbaseWalletProvider extends CoinbaseWalletProvider {
-}
-declare type CoinbaseWalletConnectorOptions = CoinbaseWalletSDKOptions & {
- jsonRpcUrl: string;
- chainId?: number;
-};
-declare class CoinbaseWalletConnector extends Connector {
- #private;
- readonly name = "coinbaseWallet";
- constructor(options: CoinbaseWalletConnectorOptions);
- connect(): Promise<{
- account: string;
- provider: CoinbaseWalletProvider;
- }>;
- getProvider(): Promise;
- disconnect(): Promise;
- /**
- * @note CoinbaseWallet will reload page if it disconnected by wallet app.
- * @todo experiment with the browser extension
- */
- onDisconnect(handler: () => void): void;
- onAccountsChanged(handler: (accounts: string[]) => void): void;
- onChainChanged(handler: (chainId: number) => void): void;
- /**
- * @todo: add addChain()
- */
- switchChain(chainId: number): Promise;
-}
-```
-
-## Gnosis Safe
-The SafeConnector supports running your Dapp inside the [Safe App](https://gnosis-safe.io/app/) with [Safe Apps SDK](https://docs.gnosis-safe.io/build/sdks)
-
-### Usage
-```ts
-const safe = new SafeConnector()
-```
-
-
-### Types
-```ts
-declare const isServer: boolean;
-declare const isIframe: boolean;
-declare const isNotSafeApp: () => boolean;
-declare class SafeConnector extends Connector {
- #private;
- readonly name = "safe";
- ready: boolean;
- constructor(options?: Opts);
- connect(): Promise<{
- account: string;
- provider: SafeAppProvider;
- }>;
- getProvider(): Promise;
- isSafeApp(): Promise;
- disconnect(): Promise;
- onDisconnect(handler: (error: ProviderRpcError) => void): void;
- onAccountsChanged(handler: (accounts: string[]) => void): void;
- onChainChanged(handler: (chainId: number) => void): void;
-}
-```
\ No newline at end of file
diff --git a/docs/api/constants.md b/docs/api/constants.md
deleted file mode 100644
index 517f8db..0000000
--- a/docs/api/constants.md
+++ /dev/null
@@ -1,52 +0,0 @@
-# Constants
-
-[source code](https://github.com/vu3th/vue-dapp/blob/main/src/constants/chainId.ts)
-
-## ChainId
-
-```ts
-export enum ChainId {
- Mainnet = 1,
- Goerli = 5,
-}
-```
-
-## CHAIN_NAMES
-```ts
-export const CHAIN_NAMES = {
- [ChainId.Mainnet]: 'Mainnet',
- [ChainId.Goerli]: 'Goerli',
-}
-```
-
-## NETWORK_DETAILS
-
-```ts
-export const NETWORK_DETAILS: { [key: number]: AddEthereumChainParameter } = {
- [ChainId.Mainnet]: {
- chainId: '0x' + ChainId.Mainnet.toString(16),
- chainName: 'Mainnet',
- rpcUrls: [
- 'https://cloudflare-eth.com',
- 'https://rpc.ankr.com/eth',
- 'https://main-rpc.linkpool.io',
- ],
- blockExplorerUrls: ['https://etherscan.io'],
- nativeCurrency: {
- symbol: 'ETH',
- decimals: 18,
- },
- },
-
- [ChainId.Goerli]: {
- chainId: '0x' + ChainId.Goerli.toString(16),
- chainName: 'Goerli',
- rpcUrls: ['https://goerli.optimism.io'],
- blockExplorerUrls: ['https://goerli.etherscan.io'],
- nativeCurrency: {
- symbol: 'ETH',
- decimals: 18,
- },
- },
-}
-```
\ No newline at end of file
diff --git a/docs/api/directives.md b/docs/api/directives.md
deleted file mode 100644
index f0167f9..0000000
--- a/docs/api/directives.md
+++ /dev/null
@@ -1,5 +0,0 @@
-# Directives
-
-- `v-click-outside`
-
-[source code](https://github.com/vu3th/vue-dapp/blob/main/src/directive.ts)
diff --git a/docs/api/plugin-options.md b/docs/api/plugin-options.md
deleted file mode 100644
index 1702001..0000000
--- a/docs/api/plugin-options.md
+++ /dev/null
@@ -1,57 +0,0 @@
-# Plugin Options
-
-- All properties in Plugin Options are optional
-
-## Types
-```ts
-type PluginOptions = {
- autoConnect: boolean;
- persistDisconnect?: boolean;
- networks: {
- [key: number]: AddEthereumChainParameter;
- };
-};
-```
-
-## autoConnect
-- Default: false
-- If set up to true, will trigger auto-connect when the page load
-
-## persistDisconnect
-- Only take effect when autoConnect is true
-- Default to true when autoConnect is true
-- If set up to false, the page would trigger auto-connect even if user clicked disconnect button and refreshed the page
-
-## networks
-[TBD]
-
-## Example
-```ts
-app.use(VueDapp, {
- autoConnect: true,
- networks: {
- 80001: {
- chainId: ethers.utils.hexValue(80001),
- blockExplorerUrls: ['https://mumbai.polygonscan.com/'],
- chainName: 'Mumbai',
- rpcUrls: ['https://rpc-mumbai.maticvigil.com/'],
- nativeCurrency: {
- name: 'Mumbai',
- decimals: 18,
- symbol: 'MATIC',
- },
- },
- 42161: {
- chainId: ethers.utils.hexValue(42161),
- blockExplorerUrls: ['https://arbiscan.io'],
- chainName: 'Arbitrum One',
- rpcUrls: ['https://arb1.arbitrum.io/rpc'],
- nativeCurrency: {
- name: 'Arbitrum',
- symbol: 'ETH',
- decimals: 18,
- },
- },
- },
-})
-```
diff --git a/docs/api/use-ethers-hooks.md b/docs/api/use-ethers-hooks.md
deleted file mode 100644
index c5d7bea..0000000
--- a/docs/api/use-ethers-hooks.md
+++ /dev/null
@@ -1,49 +0,0 @@
-# useEthersHooks
-
-Hook for watching provider from `useEthers` as follows:
-
-- `onActivated` - subscribe event when giving the provider.
-- `onDeactivated` - subscribe event when removing the provider.
-- `onChanged` - subscribe event when updating the provider.
-
-[source code](https://github.com/vu3th/vue-dapp/blob/main/src/composables/useEthersHooks.ts)
-
-## Usage
-
-```ts
-const { onActivated, onDeactivated, onChanged } = useEthersHooks()
-
-onActivated(({ provider, address }) => {
- call(provider, '0x6B175474E89094C44Da98b954EedeAC495271d0F', address)
-})
-
-onDeactivated(() => {
- console.log('deactivated')
-})
-
-onChanged(() => {
- console.log('change')
-})
-```
-## Return Value
-```ts
-{
- onActivated: (hook: OnActivatedHook) => OnActivatedHook;
- onChanged: (hook: OnChangedHook) => OnChangedHook;
- onDeactivated: (hook: OnDeactivatedHook) => OnDeactivatedHook;
-}
-```
-
-## Types
-```ts
-declare type EthersHooksContext = {
- provider: Web3Provider
- signer: Signer
- network: Network
- address: string
- balance: bigint
-}
-declare type OnActivatedHook = (context: EthersHooksContext) => void
-declare type OnChangedHook = (context: EthersHooksContext) => void
-declare type OnDeactivatedHook = () => void
-```
diff --git a/docs/api/use-ethers.md b/docs/api/use-ethers.md
deleted file mode 100644
index c9efa78..0000000
--- a/docs/api/use-ethers.md
+++ /dev/null
@@ -1,44 +0,0 @@
-# useEthers
-
-Hook for accessing the connected wallet by ethers
-
-[source code](https://github.com/vu3th/vue-dapp/blob/main/src/composables/useEthers.ts)
-
-## Usage
-```ts
-const { address, balance, chainId, isActivated } = useEthers()
-
-onActivated(() => {
- ...
-})
-
-return {
- address,
- balance
-}
-```
-
-## Return Value
-```typescript
-{
- isActivated: Ref;
- provider: Ref;
- signer: Ref;
- network: Ref<{
- name: string;
- chainId: number;
- ensAddress?: string | undefined;
- _defaultProvider?: ((providers: any, options?: any) => any) | undefined;
- } | null>;
- address: Ref;
- dnsAlias: Ref;
- balance: Ref;
- availableNetworks: Ref<{
- [key: number]: AddEthereumChainParameter;
- }>;
- chainId: vue.ComputedRef;
- activate: typeof activate;
- deactivate: () => void;
- lookupDNS: typeof lookupDNS;
-}
-```
\ No newline at end of file
diff --git a/docs/api/use-multicall.md b/docs/api/use-multicall.md
deleted file mode 100644
index da04b20..0000000
--- a/docs/api/use-multicall.md
+++ /dev/null
@@ -1,79 +0,0 @@
-# useMulticall
-
-Hook for using [Multicall2](https://github.com/makerdao/multicall/blob/master/src/Multicall2.sol)
-- `multicall` - contract of [Multicall2](https://github.com/makerdao/multicall/blob/master/src/Multicall2.sol)
-- `blockNumber`
-- `results` - return value depending on type `ContractCall[]`
-- `call` - call `tryBlockAndAggregate` on [Multicall2](https://github.com/makerdao/multicall/blob/master/src/Multicall2.sol)
-
-[source code](https://github.com/vu3th/vue-dapp/blob/main/src/composables/useMulticall.ts)
-
-## Usage
-```ts
-const calls: ContractCall[] = [
- {
- interface: ERC20Interface,
- address: '',
- method: 'name',
- },
- {
- interface: ERC20Interface,
- address: '',
- method: 'totalSupply',
- },
- {
- interface: ERC20Interface,
- address: '',
- method: 'decimals',
- },
- {
- interface: ERC20Interface,
- address: '',
- method: 'symbol',
- },
- {
- interface: ERC20Interface,
- address: '',
- method: 'balanceOf',
- args: [],
- },
-]
-
-const { call, results } = useMulticall(provider)
-
-await call(calls)
-
-const [
- [_name],
- [_totalSupply],
- [_decimals],
- [_symbol],
- { balance: _balance },
-] = results.value
-
-name.value = _name
-totalSupply.value = _totalSupply
-decimals.value = _decimals
-symbol.value = _symbol
-balance.value = (_balance as BigNumber).toBigInt()
-
-```
-
-## Types
-```ts
-declare type ContractCall = {
- interface: ContractInterface;
- address: string;
- method: string;
- args?: any[];
-};
-declare function useMulticall(provider: Web3Provider | JsonRpcProvider): {
- multicall: Multicall2;
- blockNumber: vue_demi.Ref;
- results: vue_demi.Ref<{
- [x: string]: any;
- [x: number]: any;
- }[]>;
- call: (contractCalls: ContractCall[]) => Promise;
-};
-```
diff --git a/docs/api/use-wallet.md b/docs/api/use-wallet.md
deleted file mode 100644
index 66750c2..0000000
--- a/docs/api/use-wallet.md
+++ /dev/null
@@ -1,72 +0,0 @@
-# useWallet
-
-Hook for accessing the connected wallet.
-
-[source code](https://github.com/vu3th/vue-dapp/blob/main/src/composables/useWallet.ts)
-
-## Usage
-
-```ts
-const { wallet, disconnect, onDisconnect, onAccountsChanged, onChainChanged } = useWallet()
-
-onDisconnect(() => {
- console.log('disconnect')
-})
-
-onAccountsChanged(() => {
- console.log('accounts changed')
-})
-
-onChainChanged((chainId: any) => {
- console.log('chain changed', chainId)
-})
-
-return {
- wallet
-}
-```
-
-## Return Value
-```typescript
-{
- wallet: {
- connector: {
- readonly name: string;
- readonly options: any;
- connect: () => Promise>>;
- getProvider: () => Promise;
- disconnect: () => Promise;
- onDisconnect: (handler: (...args: any[]) => any) => void;
- onAccountsChanged: (handler: (accounts: string[]) => any) => void;
- onChainChanged: (handler: (chainId: number) => any) => void;
- switchChain?: ((chainId: number) => Promise) | undefined;
- } | null;
- provider: {
- isMetaMask?: boolean | undefined;
- isStatus?: boolean | undefined;
- host?: string | undefined;
- path?: string | undefined;
- sendAsync?: ((request: {
- method: string;
- params?: any[] | undefined;
- }, callback: (error: any, response: any) => void) => void) | undefined;
- send?: ((request: {
- method: string;
- params?: any[] | undefined;
- }, callback: (error: any, response: any) => void) => void) | undefined;
- request?: ((request: {
- method: string;
- params?: any[] | undefined;
- }) => Promise) | undefined;
- } | null;
- error: string;
- status: ConnectionStatus;
- };
- connectWith: (connector: Connector) => Promise;
- disconnect: () => Promise;
- autoConnect: (connectors: Connector[]) => Promise;
- onDisconnect: (callback: OnDisconnectCallback) => void;
- onAccountsChanged: (callback: OnAccountsChangedCallback) => void;
- onChainChanged: (callback: OnChainChangedCallback) => void;
-}
-```
\ No newline at end of file
diff --git a/docs/api/utilities.md b/docs/api/utilities.md
deleted file mode 100644
index a22ef78..0000000
--- a/docs/api/utilities.md
+++ /dev/null
@@ -1,17 +0,0 @@
-# Utilities
-
-[source code](https://github.com/vu3th/vue-dapp/tree/main/src/utils)
-
-## Types
-
-```ts
-declare function shortenAddress(address: string): string;
-declare function displayEther(balance: BigNumber | bigint, fixed?: number): string;
-declare function displayChainName(chainId: number): string;
-declare function normalizeChainId(chainId: string | number): number;
-
-declare function checkInfuraId(infuraId: string): Promise;
-declare function checkChainId(chainId: number): boolean;
-```
-
-[source code](https://github.com/vu3th/vue-dapp/tree/main/src/utils)
\ No newline at end of file
diff --git a/docs/api/vd-board.md b/docs/api/vd-board.md
new file mode 100644
index 0000000..2591a94
--- /dev/null
+++ b/docs/api/vd-board.md
@@ -0,0 +1,38 @@
+# @vue-dapp/vd-board
+
+### Usage
+
+script
+```ts
+import { Board } from '@vue-dapp/vd-board'
+import '@vue-dapp/vd-board/dist/style.css'
+
+const connectors = [
+ new MetaMaskConnector()
+]
+
+function connectErrorHandler(err: any) {
+ console.error('ConnectError', err)
+}
+function autoConnectErrorHandler(err: any) {
+ console.error('AutoConnectError', err)
+}
+```
+
+template
+```vue
+
+```
+
+### Props
+
+- `dark`: boolean, defaults: false - When set to true, the board will be set to dark mode.
+- `connectors`: Connectors[], defaults: []
+- `autoConnectErrorHandler`: Function, default: () => void - catch error when a auto-connect error occurs.
+- `connectErrorHandler`: Function, default: () => void - catch error when a connect error occurs.
\ No newline at end of file
diff --git a/docs/configurations.md b/docs/configurations.md
deleted file mode 100644
index 089a8e9..0000000
--- a/docs/configurations.md
+++ /dev/null
@@ -1,127 +0,0 @@
-# Configurations
-
-## Vue CLI
-
-- Example: [vuecli + vue-dapp starter](https://github.com/chnejohnson/vue3-dapp-starter/tree/vuecli)
-
-If you're using [Vue CLI](https://cli.vuejs.org/guide/creating-a-project.html), you have to install [node-polyfill-webpack-plugin](https://www.npmjs.com/package/node-polyfill-webpack-plugin) and add the plugin in `vue.config.js` as follows.
-
-```js
-const { defineConfig } = require("@vue/cli-service");
-const NodePolyfillPlugin = require("node-polyfill-webpack-plugin");
-
-module.exports = defineConfig({
- transpileDependencies: true,
- configureWebpack: {
- plugins: [new NodePolyfillPlugin()],
- },
-});
-```
-
-## Vite
-
-- Example: [vue3-dapp-starter](https://github.com/chnejohnson/vue3-dapp-starter)
-
-If you're using [Vite](https://vitejs.dev/), you should have the following settings in `vite.config.ts`:
-
-
-```ts
-import { defineConfig } from 'vite'
-import vue from '@vitejs/plugin-vue'
-import rollupPolyfillNode from 'rollup-plugin-polyfill-node'
-import nodeStdlibBrowser from 'node-stdlib-browser'
-
-// https://vitejs.dev/config/
-export default defineConfig({
- plugins: [vue()],
- resolve: {
- // Enable polyfill node used in development to prevent from vite's browser compatibility warning
- alias: { ...nodeStdlibBrowser },
- },
- optimizeDeps: {
- // Enable polyfill node used in development, refer to https://github.com/sodatea/vite-plugin-node-stdlib-browser/blob/b17f417597c313ecd52c3e420ba8fc33bcbdae20/index.cjs#L17
- esbuildOptions: {
- inject: [require.resolve('node-stdlib-browser/helpers/esbuild/shim')],
- },
- },
- build: {
- rollupOptions: {
- plugins: [
- // Enable rollup polyfills plugin used in production bundling, refer to https://stackoverflow.com/a/72440811/10752354
- rollupPolyfillNode(),
- ],
- },
- commonjsOptions: {
- transformMixedEsModules: true, // Enable @walletconnect/web3-provider which has some code in CommonJS
- },
- },
-})
-```
-
-:::info
-Refer to [issue#20](https://github.com/vu3th/vue-dapp/issues/20)
-:::
-
-## Nuxt3
-
-- Example: [nuxt3 + vue-dapp starter](https://github.com/chnejohnson/vue3-dapp-starter/tree/nuxt3)
-
-If you're using [Nuxt3](https://v3.nuxtjs.org/), you should have following dependencies and `nuxt.config.js`.
-
-```json
-"dependencies": {
- "@nuxt/webpack-builder": "^3.0.0-rc.1",
- "assert": "^2.0.0",
- "https-browserify": "^1.0.0",
- "os-browserify": "^0.3.0",
- "stream-browserify": "^3.0.0",
- "stream-http": "^3.2.0",
- "url": "^0.11.0",
- "vue-dapp": "^0.5.2"
-},
-"devDependencies": {
- "buffer": "^6.0.3",
- "nuxt": "3.0.0-rc.1",
- "process": "^0.11.10",
- "vue-demi": "^0.12.5"
-}
-```
-
-nuxt.config.js
-
-```js
-import { defineNuxtConfig } from 'nuxt'
-const webpack = require('webpack')
-
-// https://v3.nuxtjs.org/api/configuration/nuxt.config
-export default defineNuxtConfig({
- builder: 'webpack',
- hooks: {
- 'webpack:config'(configs) {
- configs[0].resolve.fallback = {
- assert: require.resolve('assert/'),
- stream: require.resolve('stream-browserify'),
- http: require.resolve('stream-http'),
- https: require.resolve('https-browserify'),
- os: require.resolve('os-browserify/browser'),
- url: require.resolve('url/'),
- }
- configs[0].plugins.push(
- new webpack.ProvidePlugin({
- process: 'process/browser',
- }),
- )
- configs[0].plugins.push(
- new webpack.ProvidePlugin({
- Buffer: ['buffer', 'Buffer'],
- }),
- )
- },
- },
-})
-
-```
-
-:::info
-Refer to [issue#33](https://github.com/vu3th/vue-dapp/issues/33)
-:::
diff --git a/docs/contributing.md b/docs/contributing.md
index e44a6ce..fd3516e 100644
--- a/docs/contributing.md
+++ b/docs/contributing.md
@@ -1,29 +1,3 @@
-# Contributing
+# Contributing & Development Tips
-Thanks for being interested in contributing to this project!
-
-Just submit your changes via pull request and I will review them before merging.
-
-If you are making a fix on the project, you can use the `main` branch and send a pull request.
-
-If you are adding a new features, please create a new branch with a name describing your feature (`my-new-feature`), push to your branch and then submit a pull request.
-
-## Development
-
-Clone this repo to your local machine and install the dependencies.
-
-```bash
-yarn install
-```
-
-To run the demo, add `.env` for using your infura ID, and run:
-
-```bash
-yarn dev
-```
-
-To run the docs:
-
-```bash
-yarn dev:docs
-```
+- You have to use `pnpm`, and run `pnpm install` in the root directory.
diff --git a/docs/examples.md b/docs/examples.md
new file mode 100644
index 0000000..1e54ebb
--- /dev/null
+++ b/docs/examples.md
@@ -0,0 +1,4 @@
+# Examples
+
+- [vue3-dapp-starter](https://github.com/vu3th/vue3-dapp-starter)
+- [nuxt-dapp](https://github.com/vu3th/nuxt-dapp)
diff --git a/docs/index.md b/docs/index.md
index 217702d..7a42122 100644
--- a/docs/index.md
+++ b/docs/index.md
@@ -1,114 +1,52 @@
-# Getting Started
+# Vue Dapp
-## Installation
+Vue Dapp v1 is working in progress, see [Discussion#141](https://github.com/vu3th/vue-dapp/discussions/141). I would probably release a stable version by the end of 2023.
-```bash
-yarn add ethers vue-dapp
-```
+I recommend keeping an eye on [vue3-dapp-starter](https://github.com/vu3th/vue3-dapp-starter) and [nuxt-dapp](https://github.com/vu3th/nuxt-dapp), as it strives to maintain a development-friendly version whenever possible.
-If you want to support more wallet providers not only MetaMask, you should install respective packages to enable the dynamic import.
-- Support WalletConnect
-```bash
-yarn add @walletconnect/web3-provider
-```
+## Monorepo Architecture
-- Support Coinbase Wallet
-```bash
-yarn add @coinbase/wallet-sdk
-```
-
-- Support Gnosis Safe
-```bash
-yarn add @gnosis.pm/safe-apps-provider @gnosis.pm/safe-apps-sdk
-```
+library
-## Quick Start
+| Name | Description |
+| ----------------------- | ------------------------------------------------- |
+| @vue-dapp/core | useWalletStore, connector, utils, and metamask... |
+| @vue-dapp/vd-board | Vue components for connecting wallet |
+| @vue-dapp/walletconnect | WalletConnect integration |
-Step 1. Add plugin to your app:
+app
-```javascript
-import { VueDapp } from "vue-dapp";
+| Name | Description |
+| -------------- | ------------------ |
+| @vue-dapp/app | Nuxt 3 demo for v1 |
+| @vue-dapp/docs | documentation |
-const app = createApp(App);
-app.use(VueDapp);
-app.mount("#app");
-```
+legacy
-Step 2. By default, VueDapp includes `Mainnet` and `Goerli` networks, but you can extend it to include other networks:
-
-```javascript
-app.use(VueDapp, {
- autoConnect: true, // Automatically connect MetaMask wallet when the page is loaded
- networks: {
- 80001: {
- chainId: ethers.utils.hexValue(80001),
- blockExplorerUrls: ['https://mumbai.polygonscan.com/'],
- chainName: 'Mumbai',
- rpcUrls: ['https://rpc-mumbai.maticvigil.com/'],
- nativeCurrency: {
- name: 'Mumbai',
- decimals: 18,
- symbol: 'MATIC',
- },
- },
- 42161: {
- ...
- },
- },
-});
+| Name | Description |
+| ---------------- | ----------------------------- |
+| @vue-dapp/legacy | vue-dapp version below v1 |
+| @vue-dapp/demo | Vue demo for @vue-dapp/legacy |
-```
-For more examples please check:
-https://github.com/wagmi-dev/wagmi/blob/main/packages/core/src/constants/chains.ts
+## Installation
-Step 3. Add `` to your `App.vue` and add a button to open the board:
+```bash
+yarn add @vue-dapp/core @vue-dapp/vd-board
+```
-```vue
+If you want to support more wallet providers not only MetaMask, you should install respective packages.
-
-
+### WalletConnect
+```bash
+yarn add @vue-dapp/walletconnect
```
-Step 4. Construct your connectors and use composable functions in your scripts:
-
-```js
-import {
- MetaMaskConnector,
- WalletConnectConnector,
- CoinbaseWalletConnector,
- useBoard,
-} from "vue-dapp";
-
-setup()
-{
- const { open } = useBoard();
- const infuraId = "";
- const connectors = [
- new MetaMaskConnector({
- appUrl: "http://localhost:3000",
- }),
- new WalletConnectConnector({
- qrcode: true,
- rpc: {
- 1: `https://mainnet.infura.io/v3/${infuraId}`,
- 4: `https://rinkeby.infura.io/v3/${infuraId}`,
- },
- }),
- new CoinbaseWalletConnector({
- appName: "Vue Dapp",
- jsonRpcUrl: `https://mainnet.infura.io/v3/${infuraId}`,
- }),
- ];
- return {
- connectors,
- open,
- };
-}
-```
+## Support 🙏
+
+Gitcoin Grants 19: https://explorer.gitcoin.co/#/round/424/0xd4cc0dd193c7dc1d665ae244ce12d7fab337a008/0xd4cc0dd193c7dc1d665ae244ce12d7fab337a008-75
-Take a look at [Configurations](https://vue-dapp-docs.netlify.app/configurations) for more informations about Vue CLI,
-Vite, and Nuxt3 configurations.
+## MIT license
-To see the demo code, check it out [here](https://github.com/vu3th/vue-dapp/blob/main/demo/src/App.vue).
+Copyright (c) 2021-present, Johnson Chen ([@chnejohnson](https://twitter.com/chnejohnson))
diff --git a/docs/migration.md b/docs/migration.md
index 63c102c..ba182ec 100644
--- a/docs/migration.md
+++ b/docs/migration.md
@@ -1,64 +1,3 @@
-# Migrating to v0.5.x
+# Migrating to v1
-If you are coming from an earlier version of vue-dapp, in order to update to versions above 0.5.x, you will need to make sure to update the following code.
-
-## Breaking changes
-
-- You have to construct your connectors and configure third-party providers as your wallet options on board.
-- Pass your connectors to ``
-- You don't need to add plugin options anymore.
-
-### Before
-
-```ts
-// main.ts
-app.use(VueDapp, {
- infuraId: '...',
- appName: '...',
- appUrl: '...',
-})
-```
-
-App.vue
-```vue
-
-
-
-```
-
-### After
-
-```ts
-// main.ts
-app.use(VueDapp)
-
-// App.vue
-import { MetaMaskConnector, WalletConnectConnector, CoinbaseWalletConnector } from 'vue-dapp'
-
-const infuraId = ''
-
-const connectors = [
- new MetaMaskConnector({
- appUrl: 'http://localhost:3000',
- }),
- new WalletConnectConnector({
- qrcode: true,
- rpc: {
- 1: `https://mainnet.infura.io/v3/${infuraId}`,
- 4: `https://rinkeby.infura.io/v3/${infuraId}`,
- },
- }),
- new CoinbaseWalletConnector({
- appName: 'Vue Dapp',
- jsonRpcUrl: `https://mainnet.infura.io/v3/${infuraId}`,
- }),
-]
-```
-
-App.vue
-
-```vue
-
-
-
-```
\ No newline at end of file
+TBD
\ No newline at end of file
diff --git a/docs/resources.md b/docs/resources.md
deleted file mode 100644
index d04a764..0000000
--- a/docs/resources.md
+++ /dev/null
@@ -1,9 +0,0 @@
-# Resources
-
-Thanks for the inspiration provided by the following package.
-
-- [useDapp: Framework for rapid Dapp development.](https://github.com/EthWorks/useDApp)
-- [vue-tailwind-ethereum-template](https://github.com/ScopeLift/vue-tailwind-ethereum-template)
-- [web3Modal: A single Web3 / Ethereum provider solution for all Wallets](https://github.com/Web3Modal/web3modal)
-- [vue3-eth: Vue3 library for building Dapps in an ES module environment](https://github.com/samatechtw/vue3-eth)
-- [wagmi - React Hooks for Ethereum](https://wagmi.sh/)
\ No newline at end of file
diff --git a/packages/core/package.json b/packages/core/package.json
index 343072e..d8fa2a2 100644
--- a/packages/core/package.json
+++ b/packages/core/package.json
@@ -1,6 +1,6 @@
{
"name": "@vue-dapp/core",
- "version": "1.0.0-alpha.2",
+ "version": "1.0.0-alpha.8",
"description": "",
"type": "module",
"files": [
diff --git a/packages/core/src/connectors/index.ts b/packages/core/src/connectors/index.ts
deleted file mode 100644
index 0adde69..0000000
--- a/packages/core/src/connectors/index.ts
+++ /dev/null
@@ -1,3 +0,0 @@
-export * from './errors'
-export * from './connector'
-export * from './metaMask'
diff --git a/packages/core/src/constants/abi/ERC20.json b/packages/core/src/constants/abi/ERC20.json
deleted file mode 100644
index 7632903..0000000
--- a/packages/core/src/constants/abi/ERC20.json
+++ /dev/null
@@ -1,231 +0,0 @@
-{
- "contractName": "ERC20",
- "abi": [
- {
- "constant": true,
- "inputs": [],
- "name": "name",
- "outputs": [
- {
- "name": "",
- "type": "string"
- }
- ],
- "payable": false,
- "stateMutability": "view",
- "type": "function"
- },
- {
- "constant": false,
- "inputs": [
- {
- "name": "_spender",
- "type": "address"
- },
- {
- "name": "_value",
- "type": "uint256"
- }
- ],
- "name": "approve",
- "outputs": [
- {
- "name": "",
- "type": "bool"
- }
- ],
- "payable": false,
- "stateMutability": "nonpayable",
- "type": "function"
- },
- {
- "constant": true,
- "inputs": [],
- "name": "totalSupply",
- "outputs": [
- {
- "name": "",
- "type": "uint256"
- }
- ],
- "payable": false,
- "stateMutability": "view",
- "type": "function"
- },
- {
- "constant": false,
- "inputs": [
- {
- "name": "_from",
- "type": "address"
- },
- {
- "name": "_to",
- "type": "address"
- },
- {
- "name": "_value",
- "type": "uint256"
- }
- ],
- "name": "transferFrom",
- "outputs": [
- {
- "name": "",
- "type": "bool"
- }
- ],
- "payable": false,
- "stateMutability": "nonpayable",
- "type": "function"
- },
- {
- "constant": true,
- "inputs": [],
- "name": "decimals",
- "outputs": [
- {
- "name": "",
- "type": "uint8"
- }
- ],
- "payable": false,
- "stateMutability": "view",
- "type": "function"
- },
- {
- "constant": true,
- "inputs": [
- {
- "name": "_owner",
- "type": "address"
- }
- ],
- "name": "balanceOf",
- "outputs": [
- {
- "name": "balance",
- "type": "uint256"
- }
- ],
- "payable": false,
- "stateMutability": "view",
- "type": "function"
- },
- {
- "constant": true,
- "inputs": [],
- "name": "symbol",
- "outputs": [
- {
- "name": "",
- "type": "string"
- }
- ],
- "payable": false,
- "stateMutability": "view",
- "type": "function"
- },
- {
- "constant": false,
- "inputs": [
- {
- "name": "_to",
- "type": "address"
- },
- {
- "name": "_value",
- "type": "uint256"
- }
- ],
- "name": "transfer",
- "outputs": [
- {
- "name": "",
- "type": "bool"
- }
- ],
- "payable": false,
- "stateMutability": "nonpayable",
- "type": "function"
- },
- {
- "constant": true,
- "inputs": [
- {
- "name": "_owner",
- "type": "address"
- },
- {
- "name": "_spender",
- "type": "address"
- }
- ],
- "name": "allowance",
- "outputs": [
- {
- "name": "",
- "type": "uint256"
- }
- ],
- "payable": false,
- "stateMutability": "view",
- "type": "function"
- },
- {
- "payable": true,
- "stateMutability": "payable",
- "type": "fallback"
- },
- {
- "anonymous": false,
- "inputs": [
- {
- "indexed": true,
- "name": "owner",
- "type": "address"
- },
- {
- "indexed": true,
- "name": "spender",
- "type": "address"
- },
- {
- "indexed": false,
- "name": "value",
- "type": "uint256"
- }
- ],
- "name": "Approval",
- "type": "event"
- },
- {
- "anonymous": false,
- "inputs": [
- {
- "indexed": true,
- "name": "from",
- "type": "address"
- },
- {
- "indexed": true,
- "name": "to",
- "type": "address"
- },
- {
- "indexed": false,
- "name": "value",
- "type": "uint256"
- }
- ],
- "name": "Transfer",
- "type": "event"
- }
- ],
- "bytecode": "0x608060405234801561001057600080fd5b506105dd806100206000396000f3fe608060405234801561001057600080fd5b50600436106100a5576000357c01000000000000000000000000000000000000000000000000000000009004806370a082311161007857806370a0823114610166578063a457c2d71461018c578063a9059cbb146101b8578063dd62ed3e146101e4576100a5565b8063095ea7b3146100aa57806318160ddd146100ea57806323b872dd14610104578063395093511461013a575b600080fd5b6100d6600480360360408110156100c057600080fd5b50600160a060020a038135169060200135610212565b604080519115158252519081900360200190f35b6100f2610290565b60408051918252519081900360200190f35b6100d66004803603606081101561011a57600080fd5b50600160a060020a03813581169160208101359091169060400135610296565b6100d66004803603604081101561015057600080fd5b50600160a060020a03813516906020013561035f565b6100f26004803603602081101561017c57600080fd5b5035600160a060020a031661040f565b6100d6600480360360408110156101a257600080fd5b50600160a060020a03813516906020013561042a565b6100d6600480360360408110156101ce57600080fd5b50600160a060020a038135169060200135610475565b6100f2600480360360408110156101fa57600080fd5b50600160a060020a038135811691602001351661048b565b6000600160a060020a038316151561022957600080fd5b336000818152600160209081526040808320600160a060020a03881680855290835292819020869055805186815290519293927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929181900390910190a350600192915050565b60025490565b600160a060020a03831660009081526001602090815260408083203384529091528120546102ca908363ffffffff6104b616565b600160a060020a03851660009081526001602090815260408083203384529091529020556102f98484846104cb565b600160a060020a0384166000818152600160209081526040808320338085529083529281902054815190815290519293927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929181900390910190a35060019392505050565b6000600160a060020a038316151561037657600080fd5b336000908152600160209081526040808320600160a060020a03871684529091529020546103aa908363ffffffff61059816565b336000818152600160209081526040808320600160a060020a0389168085529083529281902085905580519485525191937f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929081900390910190a350600192915050565b600160a060020a031660009081526020819052604090205490565b6000600160a060020a038316151561044157600080fd5b336000908152600160209081526040808320600160a060020a03871684529091529020546103aa908363ffffffff6104b616565b60006104823384846104cb565b50600192915050565b600160a060020a03918216600090815260016020908152604080832093909416825291909152205490565b6000828211156104c557600080fd5b50900390565b600160a060020a03821615156104e057600080fd5b600160a060020a038316600090815260208190526040902054610509908263ffffffff6104b616565b600160a060020a03808516600090815260208190526040808220939093559084168152205461053e908263ffffffff61059816565b600160a060020a038084166000818152602081815260409182902094909455805185815290519193928716927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3505050565b6000828201838110156105aa57600080fd5b939250505056fea165627a7a72305820722c0187518ce2856a424bdba350d5a263c8f98fcb19cb4cc161372bc3b794c90029",
- "deployedBytecode": "0x608060405234801561001057600080fd5b50600436106100a5576000357c01000000000000000000000000000000000000000000000000000000009004806370a082311161007857806370a0823114610166578063a457c2d71461018c578063a9059cbb146101b8578063dd62ed3e146101e4576100a5565b8063095ea7b3146100aa57806318160ddd146100ea57806323b872dd14610104578063395093511461013a575b600080fd5b6100d6600480360360408110156100c057600080fd5b50600160a060020a038135169060200135610212565b604080519115158252519081900360200190f35b6100f2610290565b60408051918252519081900360200190f35b6100d66004803603606081101561011a57600080fd5b50600160a060020a03813581169160208101359091169060400135610296565b6100d66004803603604081101561015057600080fd5b50600160a060020a03813516906020013561035f565b6100f26004803603602081101561017c57600080fd5b5035600160a060020a031661040f565b6100d6600480360360408110156101a257600080fd5b50600160a060020a03813516906020013561042a565b6100d6600480360360408110156101ce57600080fd5b50600160a060020a038135169060200135610475565b6100f2600480360360408110156101fa57600080fd5b50600160a060020a038135811691602001351661048b565b6000600160a060020a038316151561022957600080fd5b336000818152600160209081526040808320600160a060020a03881680855290835292819020869055805186815290519293927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929181900390910190a350600192915050565b60025490565b600160a060020a03831660009081526001602090815260408083203384529091528120546102ca908363ffffffff6104b616565b600160a060020a03851660009081526001602090815260408083203384529091529020556102f98484846104cb565b600160a060020a0384166000818152600160209081526040808320338085529083529281902054815190815290519293927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929181900390910190a35060019392505050565b6000600160a060020a038316151561037657600080fd5b336000908152600160209081526040808320600160a060020a03871684529091529020546103aa908363ffffffff61059816565b336000818152600160209081526040808320600160a060020a0389168085529083529281902085905580519485525191937f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929081900390910190a350600192915050565b600160a060020a031660009081526020819052604090205490565b6000600160a060020a038316151561044157600080fd5b336000908152600160209081526040808320600160a060020a03871684529091529020546103aa908363ffffffff6104b616565b60006104823384846104cb565b50600192915050565b600160a060020a03918216600090815260016020908152604080832093909416825291909152205490565b6000828211156104c557600080fd5b50900390565b600160a060020a03821615156104e057600080fd5b600160a060020a038316600090815260208190526040902054610509908263ffffffff6104b616565b600160a060020a03808516600090815260208190526040808220939093559084168152205461053e908263ffffffff61059816565b600160a060020a038084166000818152602081815260409182902094909455805185815290519193928716927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3505050565b6000828201838110156105aa57600080fd5b939250505056fea165627a7a72305820722c0187518ce2856a424bdba350d5a263c8f98fcb19cb4cc161372bc3b794c90029",
- "compiler": {
- "name": "solc",
- "version": "0.5.4+commit.9549d8ff.Emscripten.clang"
- }
-}
diff --git a/packages/core/src/constants/abi/Multicall2.json b/packages/core/src/constants/abi/Multicall2.json
deleted file mode 100644
index fc177ad..0000000
--- a/packages/core/src/constants/abi/Multicall2.json
+++ /dev/null
@@ -1,165 +0,0 @@
-[
- {
- "inputs": [
- {
- "components": [
- { "internalType": "address", "name": "target", "type": "address" },
- { "internalType": "bytes", "name": "callData", "type": "bytes" }
- ],
- "internalType": "struct Multicall2.Call[]",
- "name": "calls",
- "type": "tuple[]"
- }
- ],
- "name": "aggregate",
- "outputs": [
- { "internalType": "uint256", "name": "blockNumber", "type": "uint256" },
- { "internalType": "bytes[]", "name": "returnData", "type": "bytes[]" }
- ],
- "stateMutability": "nonpayable",
- "type": "function"
- },
- {
- "inputs": [
- {
- "components": [
- { "internalType": "address", "name": "target", "type": "address" },
- { "internalType": "bytes", "name": "callData", "type": "bytes" }
- ],
- "internalType": "struct Multicall2.Call[]",
- "name": "calls",
- "type": "tuple[]"
- }
- ],
- "name": "blockAndAggregate",
- "outputs": [
- { "internalType": "uint256", "name": "blockNumber", "type": "uint256" },
- { "internalType": "bytes32", "name": "blockHash", "type": "bytes32" },
- {
- "components": [
- { "internalType": "bool", "name": "success", "type": "bool" },
- { "internalType": "bytes", "name": "returnData", "type": "bytes" }
- ],
- "internalType": "struct Multicall2.Result[]",
- "name": "returnData",
- "type": "tuple[]"
- }
- ],
- "stateMutability": "nonpayable",
- "type": "function"
- },
- {
- "inputs": [{ "internalType": "uint256", "name": "blockNumber", "type": "uint256" }],
- "name": "getBlockHash",
- "outputs": [{ "internalType": "bytes32", "name": "blockHash", "type": "bytes32" }],
- "stateMutability": "view",
- "type": "function"
- },
- {
- "inputs": [],
- "name": "getBlockNumber",
- "outputs": [{ "internalType": "uint256", "name": "blockNumber", "type": "uint256" }],
- "stateMutability": "view",
- "type": "function"
- },
- {
- "inputs": [],
- "name": "getCurrentBlockCoinbase",
- "outputs": [{ "internalType": "address", "name": "coinbase", "type": "address" }],
- "stateMutability": "view",
- "type": "function"
- },
- {
- "inputs": [],
- "name": "getCurrentBlockDifficulty",
- "outputs": [{ "internalType": "uint256", "name": "difficulty", "type": "uint256" }],
- "stateMutability": "view",
- "type": "function"
- },
- {
- "inputs": [],
- "name": "getCurrentBlockGasLimit",
- "outputs": [{ "internalType": "uint256", "name": "gaslimit", "type": "uint256" }],
- "stateMutability": "view",
- "type": "function"
- },
- {
- "inputs": [],
- "name": "getCurrentBlockTimestamp",
- "outputs": [{ "internalType": "uint256", "name": "timestamp", "type": "uint256" }],
- "stateMutability": "view",
- "type": "function"
- },
- {
- "inputs": [{ "internalType": "address", "name": "addr", "type": "address" }],
- "name": "getEthBalance",
- "outputs": [{ "internalType": "uint256", "name": "balance", "type": "uint256" }],
- "stateMutability": "view",
- "type": "function"
- },
- {
- "inputs": [],
- "name": "getLastBlockHash",
- "outputs": [{ "internalType": "bytes32", "name": "blockHash", "type": "bytes32" }],
- "stateMutability": "view",
- "type": "function"
- },
- {
- "inputs": [
- { "internalType": "bool", "name": "requireSuccess", "type": "bool" },
- {
- "components": [
- { "internalType": "address", "name": "target", "type": "address" },
- { "internalType": "bytes", "name": "callData", "type": "bytes" }
- ],
- "internalType": "struct Multicall2.Call[]",
- "name": "calls",
- "type": "tuple[]"
- }
- ],
- "name": "tryAggregate",
- "outputs": [
- {
- "components": [
- { "internalType": "bool", "name": "success", "type": "bool" },
- { "internalType": "bytes", "name": "returnData", "type": "bytes" }
- ],
- "internalType": "struct Multicall2.Result[]",
- "name": "returnData",
- "type": "tuple[]"
- }
- ],
- "stateMutability": "nonpayable",
- "type": "function"
- },
- {
- "inputs": [
- { "internalType": "bool", "name": "requireSuccess", "type": "bool" },
- {
- "components": [
- { "internalType": "address", "name": "target", "type": "address" },
- { "internalType": "bytes", "name": "callData", "type": "bytes" }
- ],
- "internalType": "struct Multicall2.Call[]",
- "name": "calls",
- "type": "tuple[]"
- }
- ],
- "name": "tryBlockAndAggregate",
- "outputs": [
- { "internalType": "uint256", "name": "blockNumber", "type": "uint256" },
- { "internalType": "bytes32", "name": "blockHash", "type": "bytes32" },
- {
- "components": [
- { "internalType": "bool", "name": "success", "type": "bool" },
- { "internalType": "bytes", "name": "returnData", "type": "bytes" }
- ],
- "internalType": "struct Multicall2.Result[]",
- "name": "returnData",
- "type": "tuple[]"
- }
- ],
- "stateMutability": "nonpayable",
- "type": "function"
- }
-]
diff --git a/packages/core/src/constants/abi/index.ts b/packages/core/src/constants/abi/index.ts
deleted file mode 100644
index 452dae2..0000000
--- a/packages/core/src/constants/abi/index.ts
+++ /dev/null
@@ -1,7 +0,0 @@
-import { Interface } from '@ethersproject/abi'
-import MULTICALL2_ABI from './Multicall2.json'
-import ERC20 from './ERC20.json'
-
-const ERC20Interface = new Interface(ERC20.abi)
-
-export { MULTICALL2_ABI, ERC20, ERC20Interface }
diff --git a/packages/core/src/constants/address.ts b/packages/core/src/constants/address.ts
deleted file mode 100644
index 98b0872..0000000
--- a/packages/core/src/constants/address.ts
+++ /dev/null
@@ -1 +0,0 @@
-export const MULTICALL2_ADDRESS = '0x5ba1e12693dc8f9c48aad8770482f4739beed696'
diff --git a/packages/core/src/constants/chainId.ts b/packages/core/src/constants/chainId.ts
deleted file mode 100644
index e76fa10..0000000
--- a/packages/core/src/constants/chainId.ts
+++ /dev/null
@@ -1,35 +0,0 @@
-import { AddEthereumChainParameter } from '../connectors'
-
-export enum ChainId {
- Mainnet = 1,
- Goerli = 5,
-}
-
-export const CHAIN_NAMES = {
- [ChainId.Mainnet]: 'Mainnet',
- [ChainId.Goerli]: 'Goerli',
-}
-
-export const NETWORK_DETAILS: { [key: number]: AddEthereumChainParameter } = {
- [ChainId.Mainnet]: {
- chainId: '0x' + ChainId.Mainnet.toString(16),
- chainName: 'Mainnet',
- rpcUrls: ['https://cloudflare-eth.com', 'https://rpc.ankr.com/eth', 'https://main-rpc.linkpool.io'],
- blockExplorerUrls: ['https://etherscan.io'],
- nativeCurrency: {
- symbol: 'ETH',
- decimals: 18,
- },
- },
-
- [ChainId.Goerli]: {
- chainId: '0x' + ChainId.Goerli.toString(16),
- chainName: 'Goerli',
- rpcUrls: ['https://goerli.optimism.io'],
- blockExplorerUrls: ['https://goerli.etherscan.io'],
- nativeCurrency: {
- symbol: 'ETH',
- decimals: 18,
- },
- },
-}
diff --git a/packages/core/src/constants/index.ts b/packages/core/src/constants/index.ts
deleted file mode 100644
index b78eb11..0000000
--- a/packages/core/src/constants/index.ts
+++ /dev/null
@@ -1,4 +0,0 @@
-export * from './chainId'
-export * from './address'
-export * from './abi'
-// source: https://github.com/EthWorks/useDApp/tree/master/packages/core/src/constants
diff --git a/packages/core/src/connectors/errors.ts b/packages/core/src/errors.ts
similarity index 100%
rename from packages/core/src/connectors/errors.ts
rename to packages/core/src/errors.ts
diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts
index 53dfabe..d30aeea 100644
--- a/packages/core/src/index.ts
+++ b/packages/core/src/index.ts
@@ -1,4 +1,4 @@
-export * from './constants'
-export * from './connectors'
+export * from './metamaskConnector'
export * from './utils'
+export * from './errors'
export * from './useWalletStore'
diff --git a/packages/core/src/connectors/metaMask.ts b/packages/core/src/metamaskConnector.ts
similarity index 92%
rename from packages/core/src/connectors/metaMask.ts
rename to packages/core/src/metamaskConnector.ts
index bf85e57..b40c80d 100644
--- a/packages/core/src/connectors/metaMask.ts
+++ b/packages/core/src/metamaskConnector.ts
@@ -1,5 +1,4 @@
-import type { NETWORK_DETAILS } from '../constants'
-import { Connector } from './connector'
+import { Connector, WalletProvider } from './types'
import {
AddChainError,
ProviderRpcError,
@@ -7,7 +6,13 @@ import {
UserRejectedRequestError,
SwitchChainError,
} from './errors'
-import { normalizeChainId, toHex } from '../utils'
+import { normalizeChainId, toHex } from './utils'
+
+declare global {
+ interface Window {
+ ethereum?: WalletProvider
+ }
+}
/**
* MetaMask
@@ -79,6 +84,7 @@ export class MetaMaskConnector extends Connectorerr).code === 4902) {
try {
- await this.addChain(
- _availableNetworks[chainId as keyof typeof NETWORK_DETAILS] as AddEthereumChainParameter,
- )
+ await this.addChain(networkDetails)
} catch (err: unknown) {
if (this.#isUserRejectedRequestError(err)) {
throw new UserRejectedRequestError(err)
@@ -213,7 +219,7 @@ export class MetaMaskConnector extends Connector | Record }): Promise
+}
export type ConnectorData = {
- account: string
provider: Provider
+ account: string
+ chainId: number
}
-export abstract class Connector {
+export abstract class Connector {
// Connector name
abstract readonly name: string
// Options to pass to the third-party provider
@@ -23,5 +25,5 @@ export abstract class Connector any): void
abstract onChainChanged(handler: (chainId: number) => any): void
- switchChain?(chainId: number): Promise
+ switchChain?(chainId: number, ...args: any[]): Promise
}
diff --git a/packages/core/src/types/global.d.ts b/packages/core/src/types/global.d.ts
deleted file mode 100644
index bc31581..0000000
--- a/packages/core/src/types/global.d.ts
+++ /dev/null
@@ -1,4 +0,0 @@
-// Global compile-time constants
-declare let __DEV__: boolean
-declare let __BROWSER__: boolean
-declare let __CI__: boolean
diff --git a/packages/core/src/types/index.ts b/packages/core/src/types/index.ts
index 6f29423..0ee3939 100644
--- a/packages/core/src/types/index.ts
+++ b/packages/core/src/types/index.ts
@@ -1 +1 @@
-export * from './provider'
+export * from './connector'
diff --git a/packages/core/src/types/multicall2/Multicall2.d.ts b/packages/core/src/types/multicall2/Multicall2.d.ts
deleted file mode 100644
index 43c46c1..0000000
--- a/packages/core/src/types/multicall2/Multicall2.d.ts
+++ /dev/null
@@ -1,573 +0,0 @@
-/* Autogenerated file. Do not edit manually. */
-/* tslint:disable */
-/* eslint-disable */
-
-import { ethers, EventFilter, Signer, BigNumber, BigNumberish, PopulatedTransaction } from 'ethers'
-import { Contract, ContractTransaction, Overrides, CallOverrides } from '@ethersproject/contracts'
-import { BytesLike } from '@ethersproject/bytes'
-import { Listener, Provider } from '@ethersproject/providers'
-import { FunctionFragment, EventFragment, Result } from '@ethersproject/abi'
-
-interface Multicall2Interface extends ethers.utils.Interface {
- functions: {
- 'aggregate(tuple[])': FunctionFragment
- 'blockAndAggregate(tuple[])': FunctionFragment
- 'getBlockHash(uint256)': FunctionFragment
- 'getBlockNumber()': FunctionFragment
- 'getCurrentBlockCoinbase()': FunctionFragment
- 'getCurrentBlockDifficulty()': FunctionFragment
- 'getCurrentBlockGasLimit()': FunctionFragment
- 'getCurrentBlockTimestamp()': FunctionFragment
- 'getEthBalance(address)': FunctionFragment
- 'getLastBlockHash()': FunctionFragment
- 'tryAggregate(bool,tuple[])': FunctionFragment
- 'tryBlockAndAggregate(bool,tuple[])': FunctionFragment
- }
-
- encodeFunctionData(functionFragment: 'aggregate', values: [{ target: string; callData: BytesLike }[]]): string
- encodeFunctionData(
- functionFragment: 'blockAndAggregate',
- values: [{ target: string; callData: BytesLike }[]],
- ): string
- encodeFunctionData(functionFragment: 'getBlockHash', values: [BigNumberish]): string
- encodeFunctionData(functionFragment: 'getBlockNumber', values?: undefined): string
- encodeFunctionData(functionFragment: 'getCurrentBlockCoinbase', values?: undefined): string
- encodeFunctionData(functionFragment: 'getCurrentBlockDifficulty', values?: undefined): string
- encodeFunctionData(functionFragment: 'getCurrentBlockGasLimit', values?: undefined): string
- encodeFunctionData(functionFragment: 'getCurrentBlockTimestamp', values?: undefined): string
- encodeFunctionData(functionFragment: 'getEthBalance', values: [string]): string
- encodeFunctionData(functionFragment: 'getLastBlockHash', values?: undefined): string
- encodeFunctionData(
- functionFragment: 'tryAggregate',
- values: [boolean, { target: string; callData: BytesLike }[]],
- ): string
- encodeFunctionData(
- functionFragment: 'tryBlockAndAggregate',
- values: [boolean, { target: string; callData: BytesLike }[]],
- ): string
-
- decodeFunctionResult(functionFragment: 'aggregate', data: BytesLike): Result
- decodeFunctionResult(functionFragment: 'blockAndAggregate', data: BytesLike): Result
- decodeFunctionResult(functionFragment: 'getBlockHash', data: BytesLike): Result
- decodeFunctionResult(functionFragment: 'getBlockNumber', data: BytesLike): Result
- decodeFunctionResult(functionFragment: 'getCurrentBlockCoinbase', data: BytesLike): Result
- decodeFunctionResult(functionFragment: 'getCurrentBlockDifficulty', data: BytesLike): Result
- decodeFunctionResult(functionFragment: 'getCurrentBlockGasLimit', data: BytesLike): Result
- decodeFunctionResult(functionFragment: 'getCurrentBlockTimestamp', data: BytesLike): Result
- decodeFunctionResult(functionFragment: 'getEthBalance', data: BytesLike): Result
- decodeFunctionResult(functionFragment: 'getLastBlockHash', data: BytesLike): Result
- decodeFunctionResult(functionFragment: 'tryAggregate', data: BytesLike): Result
- decodeFunctionResult(functionFragment: 'tryBlockAndAggregate', data: BytesLike): Result
-
- events: {}
-}
-
-export class Multicall2 extends Contract {
- connect(signerOrProvider: Signer | Provider | string): this
- attach(addressOrName: string): this
- deployed(): Promise
-
- on(event: EventFilter | string, listener: Listener): this
- once(event: EventFilter | string, listener: Listener): this
- addListener(eventName: EventFilter | string, listener: Listener): this
- removeAllListeners(eventName: EventFilter | string): this
- removeListener(eventName: any, listener: Listener): this
-
- interface: Multicall2Interface
-
- functions: {
- aggregate(calls: { target: string; callData: BytesLike }[], overrides?: Overrides): Promise
-
- 'aggregate(tuple[])'(
- calls: { target: string; callData: BytesLike }[],
- overrides?: Overrides,
- ): Promise
-
- blockAndAggregate(
- calls: { target: string; callData: BytesLike }[],
- overrides?: Overrides,
- ): Promise
-
- 'blockAndAggregate(tuple[])'(
- calls: { target: string; callData: BytesLike }[],
- overrides?: Overrides,
- ): Promise
-
- getBlockHash(
- blockNumber: BigNumberish,
- overrides?: CallOverrides,
- ): Promise<{
- blockHash: string
- 0: string
- }>
-
- 'getBlockHash(uint256)'(
- blockNumber: BigNumberish,
- overrides?: CallOverrides,
- ): Promise<{
- blockHash: string
- 0: string
- }>
-
- getBlockNumber(overrides?: CallOverrides): Promise<{
- blockNumber: BigNumber
- 0: BigNumber
- }>
-
- 'getBlockNumber()'(overrides?: CallOverrides): Promise<{
- blockNumber: BigNumber
- 0: BigNumber
- }>
-
- getCurrentBlockCoinbase(overrides?: CallOverrides): Promise<{
- coinbase: string
- 0: string
- }>
-
- 'getCurrentBlockCoinbase()'(overrides?: CallOverrides): Promise<{
- coinbase: string
- 0: string
- }>
-
- getCurrentBlockDifficulty(overrides?: CallOverrides): Promise<{
- difficulty: BigNumber
- 0: BigNumber
- }>
-
- 'getCurrentBlockDifficulty()'(overrides?: CallOverrides): Promise<{
- difficulty: BigNumber
- 0: BigNumber
- }>
-
- getCurrentBlockGasLimit(overrides?: CallOverrides): Promise<{
- gaslimit: BigNumber
- 0: BigNumber
- }>
-
- 'getCurrentBlockGasLimit()'(overrides?: CallOverrides): Promise<{
- gaslimit: BigNumber
- 0: BigNumber
- }>
-
- getCurrentBlockTimestamp(overrides?: CallOverrides): Promise<{
- timestamp: BigNumber
- 0: BigNumber
- }>
-
- 'getCurrentBlockTimestamp()'(overrides?: CallOverrides): Promise<{
- timestamp: BigNumber
- 0: BigNumber
- }>
-
- getEthBalance(
- addr: string,
- overrides?: CallOverrides,
- ): Promise<{
- balance: BigNumber
- 0: BigNumber
- }>
-
- 'getEthBalance(address)'(
- addr: string,
- overrides?: CallOverrides,
- ): Promise<{
- balance: BigNumber
- 0: BigNumber
- }>
-
- getLastBlockHash(overrides?: CallOverrides): Promise<{
- blockHash: string
- 0: string
- }>
-
- 'getLastBlockHash()'(overrides?: CallOverrides): Promise<{
- blockHash: string
- 0: string
- }>
-
- tryAggregate(
- requireSuccess: boolean,
- calls: { target: string; callData: BytesLike }[],
- overrides?: Overrides,
- ): Promise
-
- 'tryAggregate(bool,tuple[])'(
- requireSuccess: boolean,
- calls: { target: string; callData: BytesLike }[],
- overrides?: Overrides,
- ): Promise
-
- tryBlockAndAggregate(
- requireSuccess: boolean,
- calls: { target: string; callData: BytesLike }[],
- overrides?: Overrides,
- ): Promise
-
- 'tryBlockAndAggregate(bool,tuple[])'(
- requireSuccess: boolean,
- calls: { target: string; callData: BytesLike }[],
- overrides?: Overrides,
- ): Promise
- }
-
- aggregate(calls: { target: string; callData: BytesLike }[], overrides?: Overrides): Promise
-
- 'aggregate(tuple[])'(
- calls: { target: string; callData: BytesLike }[],
- overrides?: Overrides,
- ): Promise
-
- blockAndAggregate(
- calls: { target: string; callData: BytesLike }[],
- overrides?: Overrides,
- ): Promise
-
- 'blockAndAggregate(tuple[])'(
- calls: { target: string; callData: BytesLike }[],
- overrides?: Overrides,
- ): Promise
-
- getBlockHash(blockNumber: BigNumberish, overrides?: CallOverrides): Promise
-
- 'getBlockHash(uint256)'(blockNumber: BigNumberish, overrides?: CallOverrides): Promise
-
- getBlockNumber(overrides?: CallOverrides): Promise
-
- 'getBlockNumber()'(overrides?: CallOverrides): Promise
-
- getCurrentBlockCoinbase(overrides?: CallOverrides): Promise
-
- 'getCurrentBlockCoinbase()'(overrides?: CallOverrides): Promise
-
- getCurrentBlockDifficulty(overrides?: CallOverrides): Promise
-
- 'getCurrentBlockDifficulty()'(overrides?: CallOverrides): Promise
-
- getCurrentBlockGasLimit(overrides?: CallOverrides): Promise
-
- 'getCurrentBlockGasLimit()'(overrides?: CallOverrides): Promise
-
- getCurrentBlockTimestamp(overrides?: CallOverrides): Promise
-
- 'getCurrentBlockTimestamp()'(overrides?: CallOverrides): Promise
-
- getEthBalance(addr: string, overrides?: CallOverrides): Promise
-
- 'getEthBalance(address)'(addr: string, overrides?: CallOverrides): Promise
-
- getLastBlockHash(overrides?: CallOverrides): Promise
-
- 'getLastBlockHash()'(overrides?: CallOverrides): Promise
-
- tryAggregate(
- requireSuccess: boolean,
- calls: { target: string; callData: BytesLike }[],
- overrides?: Overrides,
- ): Promise
-
- 'tryAggregate(bool,tuple[])'(
- requireSuccess: boolean,
- calls: { target: string; callData: BytesLike }[],
- overrides?: Overrides,
- ): Promise
-
- tryBlockAndAggregate(
- requireSuccess: boolean,
- calls: { target: string; callData: BytesLike }[],
- overrides?: Overrides,
- ): Promise
-
- 'tryBlockAndAggregate(bool,tuple[])'(
- requireSuccess: boolean,
- calls: { target: string; callData: BytesLike }[],
- overrides?: Overrides,
- ): Promise
-
- callStatic: {
- aggregate(
- calls: { target: string; callData: BytesLike }[],
- overrides?: CallOverrides,
- ): Promise<{
- blockNumber: BigNumber
- returnData: string[]
- 0: BigNumber
- 1: string[]
- }>
-
- 'aggregate(tuple[])'(
- calls: { target: string; callData: BytesLike }[],
- overrides?: CallOverrides,
- ): Promise<{
- blockNumber: BigNumber
- returnData: string[]
- 0: BigNumber
- 1: string[]
- }>
-
- blockAndAggregate(
- calls: { target: string; callData: BytesLike }[],
- overrides?: CallOverrides,
- ): Promise<{
- blockNumber: BigNumber
- blockHash: string
- returnData: {
- success: boolean
- returnData: string
- 0: boolean
- 1: string
- }[]
- 0: BigNumber
- 1: string
- 2: { success: boolean; returnData: string; 0: boolean; 1: string }[]
- }>
-
- 'blockAndAggregate(tuple[])'(
- calls: { target: string; callData: BytesLike }[],
- overrides?: CallOverrides,
- ): Promise<{
- blockNumber: BigNumber
- blockHash: string
- returnData: {
- success: boolean
- returnData: string
- 0: boolean
- 1: string
- }[]
- 0: BigNumber
- 1: string
- 2: { success: boolean; returnData: string; 0: boolean; 1: string }[]
- }>
-
- getBlockHash(blockNumber: BigNumberish, overrides?: CallOverrides): Promise
-
- 'getBlockHash(uint256)'(blockNumber: BigNumberish, overrides?: CallOverrides): Promise
-
- getBlockNumber(overrides?: CallOverrides): Promise
-
- 'getBlockNumber()'(overrides?: CallOverrides): Promise
-
- getCurrentBlockCoinbase(overrides?: CallOverrides): Promise
-
- 'getCurrentBlockCoinbase()'(overrides?: CallOverrides): Promise
-
- getCurrentBlockDifficulty(overrides?: CallOverrides): Promise
-
- 'getCurrentBlockDifficulty()'(overrides?: CallOverrides): Promise
-
- getCurrentBlockGasLimit(overrides?: CallOverrides): Promise
-
- 'getCurrentBlockGasLimit()'(overrides?: CallOverrides): Promise
-
- getCurrentBlockTimestamp(overrides?: CallOverrides): Promise
-
- 'getCurrentBlockTimestamp()'(overrides?: CallOverrides): Promise
-
- getEthBalance(addr: string, overrides?: CallOverrides): Promise
-
- 'getEthBalance(address)'(addr: string, overrides?: CallOverrides): Promise
-
- getLastBlockHash(overrides?: CallOverrides): Promise
-
- 'getLastBlockHash()'(overrides?: CallOverrides): Promise
-
- tryAggregate(
- requireSuccess: boolean,
- calls: { target: string; callData: BytesLike }[],
- overrides?: CallOverrides,
- ): Promise<{ success: boolean; returnData: string; 0: boolean; 1: string }[]>
-
- 'tryAggregate(bool,tuple[])'(
- requireSuccess: boolean,
- calls: { target: string; callData: BytesLike }[],
- overrides?: CallOverrides,
- ): Promise<{ success: boolean; returnData: string; 0: boolean; 1: string }[]>
-
- tryBlockAndAggregate(
- requireSuccess: boolean,
- calls: { target: string; callData: BytesLike }[],
- overrides?: CallOverrides,
- ): Promise<{
- blockNumber: BigNumber
- blockHash: string
- returnData: {
- success: boolean
- returnData: string
- 0: boolean
- 1: string
- }[]
- 0: BigNumber
- 1: string
- 2: { success: boolean; returnData: string; 0: boolean; 1: string }[]
- }>
-
- 'tryBlockAndAggregate(bool,tuple[])'(
- requireSuccess: boolean,
- calls: { target: string; callData: BytesLike }[],
- overrides?: CallOverrides,
- ): Promise<{
- blockNumber: BigNumber
- blockHash: string
- returnData: {
- success: boolean
- returnData: string
- 0: boolean
- 1: string
- }[]
- 0: BigNumber
- 1: string
- 2: { success: boolean; returnData: string; 0: boolean; 1: string }[]
- }>
- }
-
- filters: {}
-
- estimateGas: {
- aggregate(calls: { target: string; callData: BytesLike }[], overrides?: Overrides): Promise
-
- 'aggregate(tuple[])'(
- calls: { target: string; callData: BytesLike }[],
- overrides?: Overrides,
- ): Promise
-
- blockAndAggregate(calls: { target: string; callData: BytesLike }[], overrides?: Overrides): Promise
-
- 'blockAndAggregate(tuple[])'(
- calls: { target: string; callData: BytesLike }[],
- overrides?: Overrides,
- ): Promise
-
- getBlockHash(blockNumber: BigNumberish, overrides?: CallOverrides): Promise
-
- 'getBlockHash(uint256)'(blockNumber: BigNumberish, overrides?: CallOverrides): Promise
-
- getBlockNumber(overrides?: CallOverrides): Promise
-
- 'getBlockNumber()'(overrides?: CallOverrides): Promise
-
- getCurrentBlockCoinbase(overrides?: CallOverrides): Promise
-
- 'getCurrentBlockCoinbase()'(overrides?: CallOverrides): Promise
-
- getCurrentBlockDifficulty(overrides?: CallOverrides): Promise
-
- 'getCurrentBlockDifficulty()'(overrides?: CallOverrides): Promise
-
- getCurrentBlockGasLimit(overrides?: CallOverrides): Promise
-
- 'getCurrentBlockGasLimit()'(overrides?: CallOverrides): Promise
-
- getCurrentBlockTimestamp(overrides?: CallOverrides): Promise
-
- 'getCurrentBlockTimestamp()'(overrides?: CallOverrides): Promise
-
- getEthBalance(addr: string, overrides?: CallOverrides): Promise
-
- 'getEthBalance(address)'(addr: string, overrides?: CallOverrides): Promise
-
- getLastBlockHash(overrides?: CallOverrides): Promise
-
- 'getLastBlockHash()'(overrides?: CallOverrides): Promise
-
- tryAggregate(
- requireSuccess: boolean,
- calls: { target: string; callData: BytesLike }[],
- overrides?: Overrides,
- ): Promise
-
- 'tryAggregate(bool,tuple[])'(
- requireSuccess: boolean,
- calls: { target: string; callData: BytesLike }[],
- overrides?: Overrides,
- ): Promise
-
- tryBlockAndAggregate(
- requireSuccess: boolean,
- calls: { target: string; callData: BytesLike }[],
- overrides?: Overrides,
- ): Promise
-
- 'tryBlockAndAggregate(bool,tuple[])'(
- requireSuccess: boolean,
- calls: { target: string; callData: BytesLike }[],
- overrides?: Overrides,
- ): Promise
- }
-
- populateTransaction: {
- aggregate(
- calls: { target: string; callData: BytesLike }[],
- overrides?: Overrides,
- ): Promise
-
- 'aggregate(tuple[])'(
- calls: { target: string; callData: BytesLike }[],
- overrides?: Overrides,
- ): Promise
-
- blockAndAggregate(
- calls: { target: string; callData: BytesLike }[],
- overrides?: Overrides,
- ): Promise
-
- 'blockAndAggregate(tuple[])'(
- calls: { target: string; callData: BytesLike }[],
- overrides?: Overrides,
- ): Promise
-
- getBlockHash(blockNumber: BigNumberish, overrides?: CallOverrides): Promise
-
- 'getBlockHash(uint256)'(blockNumber: BigNumberish, overrides?: CallOverrides): Promise
-
- getBlockNumber(overrides?: CallOverrides): Promise
-
- 'getBlockNumber()'(overrides?: CallOverrides): Promise
-
- getCurrentBlockCoinbase(overrides?: CallOverrides): Promise
-
- 'getCurrentBlockCoinbase()'(overrides?: CallOverrides): Promise
-
- getCurrentBlockDifficulty(overrides?: CallOverrides): Promise
-
- 'getCurrentBlockDifficulty()'(overrides?: CallOverrides): Promise
-
- getCurrentBlockGasLimit(overrides?: CallOverrides): Promise
-
- 'getCurrentBlockGasLimit()'(overrides?: CallOverrides): Promise
-
- getCurrentBlockTimestamp(overrides?: CallOverrides): Promise
-
- 'getCurrentBlockTimestamp()'(overrides?: CallOverrides): Promise
-
- getEthBalance(addr: string, overrides?: CallOverrides): Promise
-
- 'getEthBalance(address)'(addr: string, overrides?: CallOverrides): Promise
-
- getLastBlockHash(overrides?: CallOverrides): Promise
-
- 'getLastBlockHash()'(overrides?: CallOverrides): Promise
-
- tryAggregate(
- requireSuccess: boolean,
- calls: { target: string; callData: BytesLike }[],
- overrides?: Overrides,
- ): Promise
-
- 'tryAggregate(bool,tuple[])'(
- requireSuccess: boolean,
- calls: { target: string; callData: BytesLike }[],
- overrides?: Overrides,
- ): Promise
-
- tryBlockAndAggregate(
- requireSuccess: boolean,
- calls: { target: string; callData: BytesLike }[],
- overrides?: Overrides,
- ): Promise
-
- 'tryBlockAndAggregate(bool,tuple[])'(
- requireSuccess: boolean,
- calls: { target: string; callData: BytesLike }[],
- overrides?: Overrides,
- ): Promise
- }
-}
diff --git a/packages/core/src/types/multicall2/Multicall2Factory.ts b/packages/core/src/types/multicall2/Multicall2Factory.ts
deleted file mode 100644
index 08c125f..0000000
--- a/packages/core/src/types/multicall2/Multicall2Factory.ts
+++ /dev/null
@@ -1,348 +0,0 @@
-/* Autogenerated file. Do not edit manually. */
-/* tslint:disable */
-/* eslint-disable */
-
-import { Signer } from 'ethers'
-import { Provider, TransactionRequest } from '@ethersproject/providers'
-import { Contract, ContractFactory, Overrides } from '@ethersproject/contracts'
-
-import type { Multicall2 } from './Multicall2'
-
-export class Multicall2Factory extends ContractFactory {
- constructor(signer?: Signer) {
- super(_abi, _bytecode, signer)
- }
-
- deploy(overrides?: Overrides): Promise {
- return super.deploy(overrides || {}) as Promise
- }
- getDeployTransaction(overrides?: Overrides): TransactionRequest {
- return super.getDeployTransaction(overrides || {})
- }
- attach(address: string): Multicall2 {
- return super.attach(address) as Multicall2
- }
- connect(signer: Signer): Multicall2Factory {
- return super.connect(signer) as Multicall2Factory
- }
- static connect(address: string, signerOrProvider: Signer | Provider): Multicall2 {
- return new Contract(address, _abi, signerOrProvider) as Multicall2
- }
-}
-
-const _abi = [
- {
- inputs: [
- {
- components: [
- {
- internalType: 'address',
- name: 'target',
- type: 'address',
- },
- {
- internalType: 'bytes',
- name: 'callData',
- type: 'bytes',
- },
- ],
- internalType: 'struct Multicall2.Call[]',
- name: 'calls',
- type: 'tuple[]',
- },
- ],
- name: 'aggregate',
- outputs: [
- {
- internalType: 'uint256',
- name: 'blockNumber',
- type: 'uint256',
- },
- {
- internalType: 'bytes[]',
- name: 'returnData',
- type: 'bytes[]',
- },
- ],
- stateMutability: 'nonpayable',
- type: 'function',
- },
- {
- inputs: [
- {
- components: [
- {
- internalType: 'address',
- name: 'target',
- type: 'address',
- },
- {
- internalType: 'bytes',
- name: 'callData',
- type: 'bytes',
- },
- ],
- internalType: 'struct Multicall2.Call[]',
- name: 'calls',
- type: 'tuple[]',
- },
- ],
- name: 'blockAndAggregate',
- outputs: [
- {
- internalType: 'uint256',
- name: 'blockNumber',
- type: 'uint256',
- },
- {
- internalType: 'bytes32',
- name: 'blockHash',
- type: 'bytes32',
- },
- {
- components: [
- {
- internalType: 'bool',
- name: 'success',
- type: 'bool',
- },
- {
- internalType: 'bytes',
- name: 'returnData',
- type: 'bytes',
- },
- ],
- internalType: 'struct Multicall2.Result[]',
- name: 'returnData',
- type: 'tuple[]',
- },
- ],
- stateMutability: 'nonpayable',
- type: 'function',
- },
- {
- inputs: [
- {
- internalType: 'uint256',
- name: 'blockNumber',
- type: 'uint256',
- },
- ],
- name: 'getBlockHash',
- outputs: [
- {
- internalType: 'bytes32',
- name: 'blockHash',
- type: 'bytes32',
- },
- ],
- stateMutability: 'view',
- type: 'function',
- },
- {
- inputs: [],
- name: 'getBlockNumber',
- outputs: [
- {
- internalType: 'uint256',
- name: 'blockNumber',
- type: 'uint256',
- },
- ],
- stateMutability: 'view',
- type: 'function',
- },
- {
- inputs: [],
- name: 'getCurrentBlockCoinbase',
- outputs: [
- {
- internalType: 'address',
- name: 'coinbase',
- type: 'address',
- },
- ],
- stateMutability: 'view',
- type: 'function',
- },
- {
- inputs: [],
- name: 'getCurrentBlockDifficulty',
- outputs: [
- {
- internalType: 'uint256',
- name: 'difficulty',
- type: 'uint256',
- },
- ],
- stateMutability: 'view',
- type: 'function',
- },
- {
- inputs: [],
- name: 'getCurrentBlockGasLimit',
- outputs: [
- {
- internalType: 'uint256',
- name: 'gaslimit',
- type: 'uint256',
- },
- ],
- stateMutability: 'view',
- type: 'function',
- },
- {
- inputs: [],
- name: 'getCurrentBlockTimestamp',
- outputs: [
- {
- internalType: 'uint256',
- name: 'timestamp',
- type: 'uint256',
- },
- ],
- stateMutability: 'view',
- type: 'function',
- },
- {
- inputs: [
- {
- internalType: 'address',
- name: 'addr',
- type: 'address',
- },
- ],
- name: 'getEthBalance',
- outputs: [
- {
- internalType: 'uint256',
- name: 'balance',
- type: 'uint256',
- },
- ],
- stateMutability: 'view',
- type: 'function',
- },
- {
- inputs: [],
- name: 'getLastBlockHash',
- outputs: [
- {
- internalType: 'bytes32',
- name: 'blockHash',
- type: 'bytes32',
- },
- ],
- stateMutability: 'view',
- type: 'function',
- },
- {
- inputs: [
- {
- internalType: 'bool',
- name: 'requireSuccess',
- type: 'bool',
- },
- {
- components: [
- {
- internalType: 'address',
- name: 'target',
- type: 'address',
- },
- {
- internalType: 'bytes',
- name: 'callData',
- type: 'bytes',
- },
- ],
- internalType: 'struct Multicall2.Call[]',
- name: 'calls',
- type: 'tuple[]',
- },
- ],
- name: 'tryAggregate',
- outputs: [
- {
- components: [
- {
- internalType: 'bool',
- name: 'success',
- type: 'bool',
- },
- {
- internalType: 'bytes',
- name: 'returnData',
- type: 'bytes',
- },
- ],
- internalType: 'struct Multicall2.Result[]',
- name: 'returnData',
- type: 'tuple[]',
- },
- ],
- stateMutability: 'nonpayable',
- type: 'function',
- },
- {
- inputs: [
- {
- internalType: 'bool',
- name: 'requireSuccess',
- type: 'bool',
- },
- {
- components: [
- {
- internalType: 'address',
- name: 'target',
- type: 'address',
- },
- {
- internalType: 'bytes',
- name: 'callData',
- type: 'bytes',
- },
- ],
- internalType: 'struct Multicall2.Call[]',
- name: 'calls',
- type: 'tuple[]',
- },
- ],
- name: 'tryBlockAndAggregate',
- outputs: [
- {
- internalType: 'uint256',
- name: 'blockNumber',
- type: 'uint256',
- },
- {
- internalType: 'bytes32',
- name: 'blockHash',
- type: 'bytes32',
- },
- {
- components: [
- {
- internalType: 'bool',
- name: 'success',
- type: 'bool',
- },
- {
- internalType: 'bytes',
- name: 'returnData',
- type: 'bytes',
- },
- ],
- internalType: 'struct Multicall2.Result[]',
- name: 'returnData',
- type: 'tuple[]',
- },
- ],
- stateMutability: 'nonpayable',
- type: 'function',
- },
-]
-
-const _bytecode =
- '0x608060405234801561001057600080fd5b5061119f806100206000396000f3fe608060405234801561001057600080fd5b50600436106100b45760003560e01c806372425d9d1161007157806372425d9d146101a657806386d516e8146101c4578063a8b0574e146101e2578063bce38bd714610200578063c3077fa914610230578063ee82ac5e14610262576100b4565b80630f28c97d146100b9578063252dba42146100d757806327e86d6e14610108578063399542e91461012657806342cbb15c146101585780634d2301cc14610176575b600080fd5b6100c1610292565b6040516100ce9190610d46565b60405180910390f35b6100f160048036038101906100ec919061099e565b61029a565b6040516100ff929190610d61565b60405180910390f35b6101106104bb565b60405161011d9190610ceb565b60405180910390f35b610140600480360381019061013b91906109df565b6104d0565b60405161014f93929190610d91565b60405180910390f35b6101606104ef565b60405161016d9190610d46565b60405180910390f35b610190600480360381019061018b9190610975565b6104f7565b60405161019d9190610d46565b60405180910390f35b6101ae610518565b6040516101bb9190610d46565b60405180910390f35b6101cc610520565b6040516101d99190610d46565b60405180910390f35b6101ea610528565b6040516101f79190610cae565b60405180910390f35b61021a600480360381019061021591906109df565b610530565b6040516102279190610cc9565b60405180910390f35b61024a6004803603810190610245919061099e565b610770565b60405161025993929190610d91565b60405180910390f35b61027c60048036038101906102779190610a33565b610793565b6040516102899190610ceb565b60405180910390f35b600042905090565b60006060439150825167ffffffffffffffff8111156102e2577f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b60405190808252806020026020018201604052801561031557816020015b60608152602001906001900390816103005790505b50905060005b83518110156104b557600080858381518110610360577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60200260200101516000015173ffffffffffffffffffffffffffffffffffffffff168684815181106103bb577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b6020026020010151602001516040516103d49190610c97565b6000604051808303816000865af19150503d8060008114610411576040519150601f19603f3d011682016040523d82523d6000602084013e610416565b606091505b50915091508161045b576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161045290610d26565b60405180910390fd5b80848481518110610495577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b6020026020010181905250505080806104ad90610ff4565b91505061031b565b50915091565b60006001436104ca9190610efb565b40905090565b6000806060439250434091506104e68585610530565b90509250925092565b600043905090565b60008173ffffffffffffffffffffffffffffffffffffffff16319050919050565b600044905090565b600045905090565b600041905090565b6060815167ffffffffffffffff811115610573577f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6040519080825280602002602001820160405280156105ac57816020015b61059961079e565b8152602001906001900390816105915790505b50905060005b8251811015610769576000808483815181106105f7577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60200260200101516000015173ffffffffffffffffffffffffffffffffffffffff16858481518110610652577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60200260200101516020015160405161066b9190610c97565b6000604051808303816000865af19150503d80600081146106a8576040519150601f19603f3d011682016040523d82523d6000602084013e6106ad565b606091505b509150915085156106f957816106f8576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016106ef90610d06565b60405180910390fd5b5b6040518060400160405280831515815260200182815250848481518110610749577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60200260200101819052505050808061076190610ff4565b9150506105b2565b5092915050565b60008060606107806001856104d0565b8093508194508295505050509193909250565b600081409050919050565b6040518060400160405280600015158152602001606081525090565b60006107cd6107c884610df4565b610dcf565b905080838252602082019050828560208602820111156107ec57600080fd5b60005b8581101561083657813567ffffffffffffffff81111561080e57600080fd5b80860161081b89826108fc565b855260208501945060208401935050506001810190506107ef565b5050509392505050565b600061085361084e84610e20565b610dcf565b90508281526020810184848401111561086b57600080fd5b610876848285610f81565b509392505050565b60008135905061088d81611124565b92915050565b600082601f8301126108a457600080fd5b81356108b48482602086016107ba565b91505092915050565b6000813590506108cc8161113b565b92915050565b600082601f8301126108e357600080fd5b81356108f3848260208601610840565b91505092915050565b60006040828403121561090e57600080fd5b6109186040610dcf565b905060006109288482850161087e565b600083015250602082013567ffffffffffffffff81111561094857600080fd5b610954848285016108d2565b60208301525092915050565b60008135905061096f81611152565b92915050565b60006020828403121561098757600080fd5b60006109958482850161087e565b91505092915050565b6000602082840312156109b057600080fd5b600082013567ffffffffffffffff8111156109ca57600080fd5b6109d684828501610893565b91505092915050565b600080604083850312156109f257600080fd5b6000610a00858286016108bd565b925050602083013567ffffffffffffffff811115610a1d57600080fd5b610a2985828601610893565b9150509250929050565b600060208284031215610a4557600080fd5b6000610a5384828501610960565b91505092915050565b6000610a688383610b9b565b905092915050565b6000610a7c8383610c4b565b905092915050565b610a8d81610f2f565b82525050565b6000610a9e82610e71565b610aa88185610eac565b935083602082028501610aba85610e51565b8060005b85811015610af65784840389528151610ad78582610a5c565b9450610ae283610e92565b925060208a01995050600181019050610abe565b50829750879550505050505092915050565b6000610b1382610e7c565b610b1d8185610ebd565b935083602082028501610b2f85610e61565b8060005b85811015610b6b5784840389528151610b4c8582610a70565b9450610b5783610e9f565b925060208a01995050600181019050610b33565b50829750879550505050505092915050565b610b8681610f41565b82525050565b610b9581610f4d565b82525050565b6000610ba682610e87565b610bb08185610ece565b9350610bc0818560208601610f90565b610bc98161109b565b840191505092915050565b6000610bdf82610e87565b610be98185610edf565b9350610bf9818560208601610f90565b80840191505092915050565b6000610c12602183610eea565b9150610c1d826110ac565b604082019050919050565b6000610c35602083610eea565b9150610c40826110fb565b602082019050919050565b6000604083016000830151610c636000860182610b7d565b5060208301518482036020860152610c7b8282610b9b565b9150508091505092915050565b610c9181610f77565b82525050565b6000610ca38284610bd4565b915081905092915050565b6000602082019050610cc36000830184610a84565b92915050565b60006020820190508181036000830152610ce38184610b08565b905092915050565b6000602082019050610d006000830184610b8c565b92915050565b60006020820190508181036000830152610d1f81610c05565b9050919050565b60006020820190508181036000830152610d3f81610c28565b9050919050565b6000602082019050610d5b6000830184610c88565b92915050565b6000604082019050610d766000830185610c88565b8181036020830152610d888184610a93565b90509392505050565b6000606082019050610da66000830186610c88565b610db36020830185610b8c565b8181036040830152610dc58184610b08565b9050949350505050565b6000610dd9610dea565b9050610de58282610fc3565b919050565b6000604051905090565b600067ffffffffffffffff821115610e0f57610e0e61106c565b5b602082029050602081019050919050565b600067ffffffffffffffff821115610e3b57610e3a61106c565b5b610e448261109b565b9050602081019050919050565b6000819050602082019050919050565b6000819050602082019050919050565b600081519050919050565b600081519050919050565b600081519050919050565b6000602082019050919050565b6000602082019050919050565b600082825260208201905092915050565b600082825260208201905092915050565b600082825260208201905092915050565b600081905092915050565b600082825260208201905092915050565b6000610f0682610f77565b9150610f1183610f77565b925082821015610f2457610f2361103d565b5b828203905092915050565b6000610f3a82610f57565b9050919050565b60008115159050919050565b6000819050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b82818337600083830152505050565b60005b83811015610fae578082015181840152602081019050610f93565b83811115610fbd576000848401525b50505050565b610fcc8261109b565b810181811067ffffffffffffffff82111715610feb57610fea61106c565b5b80604052505050565b6000610fff82610f77565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8214156110325761103161103d565b5b600182019050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6000601f19601f8301169050919050565b7f4d756c746963616c6c32206167677265676174653a2063616c6c206661696c6560008201527f6400000000000000000000000000000000000000000000000000000000000000602082015250565b7f4d756c746963616c6c206167677265676174653a2063616c6c206661696c6564600082015250565b61112d81610f2f565b811461113857600080fd5b50565b61114481610f41565b811461114f57600080fd5b50565b61115b81610f77565b811461116657600080fd5b5056fea26469706673582212209343de41d7a3136444d0e14e30bc3228ba06229fe97cbd8649e934a11cef16f364736f6c63430008040033'
diff --git a/packages/core/src/types/provider.ts b/packages/core/src/types/provider.ts
deleted file mode 100644
index 1130164..0000000
--- a/packages/core/src/types/provider.ts
+++ /dev/null
@@ -1,7 +0,0 @@
-// copied from ethers.js
-export type WalletProvider = {
- /**
- * See [[link-eip-1193]] for details on this method.
- */
- request(request: { method: string; params?: Array | Record }): Promise
-}
diff --git a/packages/core/src/types/vue-shim.d.ts b/packages/core/src/types/vue-shim.d.ts
deleted file mode 100644
index 9392998..0000000
--- a/packages/core/src/types/vue-shim.d.ts
+++ /dev/null
@@ -1,5 +0,0 @@
-declare module '*.vue' {
- import { DefineComponent } from 'vue'
- const component: DefineComponent, Record, any>
- export default component
-}
diff --git a/packages/core/src/useWalletStore.ts b/packages/core/src/useWalletStore.ts
index 4b7115e..9198732 100644
--- a/packages/core/src/useWalletStore.ts
+++ b/packages/core/src/useWalletStore.ts
@@ -1,19 +1,28 @@
-import { computed, markRaw, ref, watch } from 'vue'
+import { computed, markRaw, ref, toRaw, watch } from 'vue'
import { defineStore } from 'pinia'
-import { Connector, ConnectorNotFoundError, ConnectError } from './connectors'
+import { Connector } from './types'
+import { ConnectorNotFoundError, ConnectError, AutoConnectError } from './errors'
import { WalletProvider } from './types'
import invariant from 'tiny-invariant'
+import { normalizeChainId } from './utils'
+import { MetaMaskConnector } from './metamaskConnector'
export type ConnectionStatus = 'idle' | 'connecting' | 'connected'
export type HookContext = {
provider: WalletProvider
address: string
+ chainId: number
}
-export type OnActivatedHook = (context: HookContext) => void
+export type OnConnectedHook = (context: HookContext) => void
export type OnChangedHook = (context: HookContext) => void
-export type OnDeactivatedHook = () => void
+export type OnDisconnectHook = () => void
+
+// feat: callbacks
+export type OnDisconnectCallback = (...args: any[]) => void
+export type OnAccountsChangedCallback = (accounts: string[]) => void
+export type OnChainChangedCallback = (chainId: number) => void
/**
* Pinia Setup Store
@@ -21,11 +30,23 @@ export type OnDeactivatedHook = () => void
* - dealing with SSR https://pinia.vuejs.org/cookbook/composables.html#SSR
*/
export const useWalletStore = defineStore('vd-wallet', () => {
+ const status = ref('idle')
+ const error = ref('')
+
+ const dumb = ref(true)
+ function setDumb(isDumb: boolean) {
+ dumb.value = isDumb
+ }
+
const connector = ref(null)
const provider = ref(null)
- const status = ref('idle')
const address = ref('')
- const error = ref('')
+ const chainId = ref(-1)
+
+ // feat: callbacks
+ const onDisconnectCallback = ref(null)
+ const onAccountsChangedCallback = ref(null)
+ const onChainChangedCallback = ref(null)
const isConnected = computed(() => status.value === 'connected')
@@ -36,11 +57,12 @@ export const useWalletStore = defineStore('vd-wallet', () => {
try {
if (!_connector) throw new ConnectorNotFoundError()
- const { provider: _provider, account } = await _connector.connect(timeout)
+ const { provider: _provider, account, chainId: _chainId } = await _connector.connect(timeout)
connector.value = markRaw(_connector)
provider.value = markRaw(_provider)
address.value = account
+ chainId.value = normalizeChainId(_chainId)
} catch (err: any) {
await disconnect() // will also resetWallet()
error.value = err.message
@@ -48,6 +70,33 @@ export const useWalletStore = defineStore('vd-wallet', () => {
}
status.value = 'connected'
+ localStorage.removeItem('VUE_DAPP__hasDisconnected')
+
+ // feat: callbacks
+ connector.value.onDisconnect((...args: any[]) => {
+ onDisconnectCallback.value && onDisconnectCallback.value(...args)
+ /**
+ * Exclude metamask to disconnect on this event
+ * @note MetaMask disconnect event would be triggered when the specific chain changed (like L2 network),
+ * so if we disconnect in this case, it would fail to reactivate ethers when chain changed
+ * because the wallet state was cleared.
+ * @todo better solution
+ */
+ if (connector.value?.name === 'metaMask') {
+ return
+ }
+ disconnect()
+ })
+
+ connector.value.onAccountsChanged(async (accounts: string[]) => {
+ onAccountsChangedCallback.value && onAccountsChangedCallback.value(accounts)
+ address.value = accounts[0]
+ })
+
+ connector.value.onChainChanged(async (_chainId: number) => {
+ onChainChangedCallback.value && onChainChangedCallback.value(normalizeChainId(_chainId))
+ chainId.value = normalizeChainId(_chainId)
+ })
}
async function disconnect() {
@@ -60,8 +109,8 @@ export const useWalletStore = defineStore('vd-wallet', () => {
}
}
resetWallet()
- // @todo
- // persistDisconnect.value && localStorage.setItem('VUE_DAPP__hasDisconnected', 'true')
+
+ localStorage.setItem('VUE_DAPP__hasDisconnected', 'true')
}
async function resetWallet() {
@@ -71,54 +120,96 @@ export const useWalletStore = defineStore('vd-wallet', () => {
address.value = ''
}
- // @todo
- function autoConnect(connectors: Connector[]) {
- console.log('autoConnect')
+ async function autoConnect(connectors: Connector[]) {
+ if (localStorage.getItem('VUE_DAPP__hasDisconnected')) {
+ !dumb.value && console.warn('No auto-connect: has disconnected') // eslint-disable-line
+ return
+ }
+
+ const metamask = connectors.find(conn => conn.name === 'metaMask') as MetaMaskConnector | undefined
+
+ if (metamask) {
+ try {
+ const isConnected = await MetaMaskConnector.checkConnection()
+ if (isConnected) {
+ await connectWith(metamask)
+ } else if (!dumb.value) {
+ console.warn('No auto-connect to MetaMask: not connected')
+ }
+ } catch (err: any) {
+ throw new AutoConnectError(err)
+ }
+ } else if (!dumb.value) {
+ console.warn('No auto-connect to MetaMask: connector not found')
+ }
}
// ========================= hooks =========================
- const onActivatedHook = ref(null)
- const onDeactivatedHook = ref(null)
+ const onConnectedHook = ref(null)
+ const onDisconnectHook = ref(null)
const onChangedHook = ref(null)
watch(isConnected, (val, oldVal) => {
if (val && !oldVal) {
- invariant(address.value, 'VueDappError: useWalletStore-watch-isConnected-address')
invariant(provider.value, 'VueDappError: useWalletStore-watch-isConnected-provider')
+ invariant(address.value, 'VueDappError: useWalletStore-watch-isConnected-address')
+ invariant(chainId.value, 'VueDappError: useWalletStore-watch-isConnected-chainId')
- onActivatedHook.value &&
- onActivatedHook.value({
- provider: provider.value,
- address: address.value,
+ onConnectedHook.value &&
+ onConnectedHook.value({
+ provider: toRaw(provider.value),
+ address: toRaw(address.value),
+ chainId: toRaw(chainId.value),
})
+ } else {
+ onDisconnectHook.value && onDisconnectHook.value()
}
})
- watch(provider, (val, oldVal) => {
+ watch(address, (val, oldVal) => {
if (oldVal && val) {
+ invariant(provider.value, 'VueDappError: useWalletStore-watch-address-provider')
+ invariant(address.value, 'VueDappError: useWalletStore-watch-address-address')
+ invariant(chainId.value, 'VueDappError: useWalletStore-watch-address-chainId')
+
onChangedHook.value &&
onChangedHook.value({
- provider: val,
- address: address.value,
+ provider: toRaw(provider.value),
+ address: toRaw(address.value),
+ chainId: toRaw(chainId.value),
})
- } else if (oldVal && !val) {
- onDeactivatedHook.value && onDeactivatedHook.value()
}
})
- const onActivated = (hook: OnActivatedHook) => (onActivatedHook.value = hook)
+ watch(chainId, (val, oldVal) => {
+ if (val && oldVal > 0) {
+ invariant(provider.value, 'VueDappError: useWalletStore-watch-chainId-provider')
+ invariant(address.value, 'VueDappError: useWalletStore-watch-chainId-address')
+ invariant(chainId.value, 'VueDappError: useWalletStore-watch-chainId-chainId')
+
+ onChangedHook.value &&
+ onChangedHook.value({
+ provider: toRaw(provider.value),
+ address: toRaw(address.value),
+ chainId: toRaw(chainId.value),
+ })
+ }
+ })
+
+ const onActivated = (hook: OnConnectedHook) => (onConnectedHook.value = hook)
const onChanged = (hook: OnChangedHook) => (onChangedHook.value = hook)
- const onDeactivated = (hook: OnDeactivatedHook) => (onDeactivatedHook.value = hook)
+ const onDeactivated = (hook: OnDisconnectHook) => (onDisconnectHook.value = hook)
return {
// state
+ isConnected,
+ error,
+
provider,
connector,
status,
address,
- error,
- isConnected,
// wallet functions
connectWith,
@@ -126,9 +217,17 @@ export const useWalletStore = defineStore('vd-wallet', () => {
resetWallet,
autoConnect,
- // hooks
+ // hooks (for watcher)
onActivated,
onDeactivated,
onChanged,
+
+ // callbacks (for listener)
+ onDisconnectCallback,
+ onAccountsChangedCallback,
+ onChainChangedCallback,
+
+ // others
+ setDumb,
}
})
diff --git a/packages/core/src/utils/check.ts b/packages/core/src/utils/check.ts
index 7f27ada..7ad977f 100644
--- a/packages/core/src/utils/check.ts
+++ b/packages/core/src/utils/check.ts
@@ -17,7 +17,7 @@ export async function checkInfuraId(infuraId: string) {
return data.result
}
-export function checkChainId(chainId: number) {
- // const { availableNetworks } = useEthers()
- // return chainId in availableNetworks.value
-}
+// export function checkChainId(chainId: number) {
+// // const { availableNetworks } = useEthers()
+// // return chainId in availableNetworks.value
+// }
diff --git a/packages/core/src/utils/format.ts b/packages/core/src/utils/format.ts
index d80d52a..b1eecb9 100644
--- a/packages/core/src/utils/format.ts
+++ b/packages/core/src/utils/format.ts
@@ -1,4 +1,4 @@
-import { checkChainId } from './check'
+// import { checkChainId } from './check'
/**
* Convert a number to a hexadecimal value
@@ -12,20 +12,17 @@ export function shortenAddress(address: string): string {
return address.slice(0, 6) + '...' + address.slice(-4)
}
-export function displayChainName(chainId: number) {
- if (!checkChainId(chainId)) {
- return ''
- }
- // dev
- // const { availableNetworks } = useEthers()
- // return availableNetworks.value[chainId].chainName.toLowerCase()
-}
-
-export function normalizeChainId(chainId: string | number) {
- if (typeof chainId === 'string') {
- const isHex = chainId.trim().substring(0, 2)
+// export function displayChainName(chainId: number) {
+// if (!checkChainId(chainId)) {
+// return ''
+// }
+// // dev
+// // const { availableNetworks } = useEthers()
+// // return availableNetworks.value[chainId].chainName.toLowerCase()
+// }
- return Number.parseInt(chainId, isHex === '0x' ? 16 : 10)
- }
+export function normalizeChainId(chainId: string | number | bigint) {
+ if (typeof chainId === 'string') return Number.parseInt(chainId, chainId.trim().substring(0, 2) === '0x' ? 16 : 10)
+ if (typeof chainId === 'bigint') return Number(chainId)
return chainId
}
diff --git a/packages/vd-board/package.json b/packages/vd-board/package.json
index 2452d7e..6236627 100644
--- a/packages/vd-board/package.json
+++ b/packages/vd-board/package.json
@@ -1,6 +1,6 @@
{
"name": "@vue-dapp/vd-board",
- "version": "1.0.0-alpha.2",
+ "version": "1.0.0-alpha.4",
"type": "module",
"files": [
"dist"
@@ -12,7 +12,8 @@
".": {
"import": "./dist/vd-board.js",
"require": "./dist/vd-board.umd.cjs"
- }
+ },
+ "./dist/style.css": "./dist/style.css"
},
"publishConfig": {
"access": "public"
@@ -20,6 +21,7 @@
"scripts": {
"dev": "vite",
"build": "vite build",
+ "watch": "vite build --watch",
"preview": "vite preview"
},
"devDependencies": {
@@ -29,7 +31,6 @@
"typescript": "^5.1.3",
"vite": "^4.5.0",
"vite-plugin-dts": "^3.6.2",
- "vite-plugin-style-inject": "^0.0.1",
"vue": "^3.3.6",
"vue-tsc": "^0.29.8"
},
diff --git a/packages/vd-board/src/components/Board.vue b/packages/vd-board/src/components/Board.vue
index 56d1b6c..42ef3a3 100644
--- a/packages/vd-board/src/components/Board.vue
+++ b/packages/vd-board/src/components/Board.vue
@@ -1,5 +1,5 @@