wagmi 0.0.9 → 0.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +48 -24
- package/dist/declarations/src/context.d.ts +13 -4
- package/dist/declarations/src/hooks/accounts/useAccount.d.ts +1 -0
- package/dist/declarations/src/hooks/accounts/useBalance.d.ts +8 -3
- package/dist/declarations/src/hooks/accounts/useSignMessage.d.ts +1 -0
- package/dist/declarations/src/hooks/contracts/index.d.ts +2 -0
- package/dist/declarations/src/hooks/contracts/useContract.d.ts +3 -0
- package/dist/declarations/src/hooks/contracts/useContractEvent.d.ts +1 -0
- package/dist/declarations/src/hooks/contracts/useContractRead.d.ts +17 -0
- package/dist/declarations/src/hooks/contracts/useContractWrite.d.ts +15 -0
- package/dist/declarations/src/hooks/ens/useEnsAvatar.d.ts +2 -0
- package/dist/declarations/src/hooks/ens/useEnsLookup.d.ts +2 -0
- package/dist/declarations/src/hooks/ens/useEnsResolver.d.ts +2 -0
- package/dist/declarations/src/hooks/index.d.ts +1 -1
- package/dist/declarations/src/hooks/network-status/useBlockNumber.d.ts +2 -0
- package/dist/declarations/src/hooks/network-status/useFeeData.d.ts +3 -0
- package/dist/declarations/src/hooks/transactions/useTransaction.d.ts +1 -0
- package/dist/declarations/src/hooks/transactions/useWaitForTransaction.d.ts +8 -1
- package/dist/declarations/src/index.d.ts +1 -1
- package/dist/wagmi.cjs.dev.js +258 -127
- package/dist/wagmi.cjs.prod.js +258 -127
- package/dist/wagmi.esm.js +257 -128
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -13,51 +13,75 @@
|
|
|
13
13
|
</a>
|
|
14
14
|
</p>
|
|
15
15
|
|
|
16
|
+
# wagmi
|
|
17
|
+
|
|
18
|
+
**React Hooks library for Ethereum, built on [ethers.js](https://github.com/ethers-io/ethers.js).**
|
|
19
|
+
|
|
20
|
+
🚀 Hooks for connecting wallets, signing messages, sending transactions, etc.
|
|
21
|
+
|
|
22
|
+
💼 Built-in wallet connectors for MetaMask, WalletConnect, and Coinbase Wallet
|
|
23
|
+
|
|
24
|
+
🌀 Auto-refresh data on wallet and network changes
|
|
25
|
+
|
|
26
|
+
🦄 TypeScript ready
|
|
27
|
+
|
|
28
|
+
💨 Zero-dependencies (besides ethers.js peer dependency)
|
|
29
|
+
|
|
30
|
+
🌳 Test suite and documentation
|
|
31
|
+
|
|
32
|
+
📖 MIT License
|
|
33
|
+
|
|
16
34
|
## Documentation
|
|
17
35
|
|
|
18
36
|
Visit https://wagmi-xyz.vercel.app to view the full documentation.
|
|
19
37
|
|
|
20
38
|
## Usage
|
|
21
39
|
|
|
40
|
+
1. Install the dependencies.
|
|
41
|
+
|
|
22
42
|
```bash
|
|
23
43
|
pnpm add wagmi ethers
|
|
24
44
|
```
|
|
25
45
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
```bash
|
|
29
|
-
pnpm i
|
|
30
|
-
pnpm dev
|
|
31
|
-
```
|
|
46
|
+
2. Wrap your app with the `Provider` component.
|
|
32
47
|
|
|
33
|
-
|
|
48
|
+
```tsx
|
|
49
|
+
import { Provider } from 'wagmi'
|
|
34
50
|
|
|
35
|
-
|
|
36
|
-
|
|
51
|
+
const App = () => (
|
|
52
|
+
<Provider>
|
|
53
|
+
<YourRoutes />
|
|
54
|
+
</Provider>
|
|
55
|
+
)
|
|
37
56
|
```
|
|
38
57
|
|
|
39
|
-
|
|
58
|
+
3. Use hooks.
|
|
40
59
|
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
pnpm dev:example:vite-react
|
|
44
|
-
```
|
|
60
|
+
```tsx
|
|
61
|
+
import { useAccount } from 'wagmi'
|
|
45
62
|
|
|
46
|
-
|
|
63
|
+
const App = () => {
|
|
64
|
+
const [{ data, error, loading }, disconnect] = useAccount({
|
|
65
|
+
fetchEns: true,
|
|
66
|
+
})
|
|
47
67
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
pnpm test:watch
|
|
68
|
+
return ...
|
|
69
|
+
}
|
|
51
70
|
```
|
|
52
71
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
[Add secrets](https://github.com/tmm/wagmi/settings/secrets/actions) to GitHub:
|
|
72
|
+
Every component inside the `Provider` is set up with the default `InjectedConnector` for connecting wallets and ethers.js [Default Provider](https://docs.ethers.io/v5/api/providers/#providers-getDefaultProvider) for fetching data.
|
|
56
73
|
|
|
57
|
-
|
|
58
|
-
NPM_TOKEN
|
|
59
|
-
```
|
|
74
|
+
Want to learn more? Check out the [guides](https://wagmi-xyz.vercel.app/guides/connect-wallet) or browse the [API docs](https://wagmi-xyz.vercel.app/docs/provider).
|
|
60
75
|
|
|
61
76
|
## Thanks
|
|
62
77
|
|
|
63
78
|
- [ricmoo.eth](https://twitter.com/ricmoo) for creating and continued work on [ethers.js](https://github.com/ethers-io/ethers.js)
|
|
79
|
+
- [Mirror](https://mirror.xyz) for creating space to do good work
|
|
80
|
+
|
|
81
|
+
## License
|
|
82
|
+
|
|
83
|
+
MIT.
|
|
84
|
+
|
|
85
|
+
<br />
|
|
86
|
+
|
|
87
|
+
wagmi
|
|
@@ -29,13 +29,22 @@ export declare const Context: React.Context<ContextValue | null>;
|
|
|
29
29
|
export declare type Props = {
|
|
30
30
|
/** Enables reconnecting to last used connector on mount */
|
|
31
31
|
autoConnect?: boolean;
|
|
32
|
-
/**
|
|
32
|
+
/**
|
|
33
|
+
* Key for saving connector preference to browser
|
|
34
|
+
* @default 'wagmi.wallet'
|
|
35
|
+
*/
|
|
33
36
|
connectorStorageKey?: string;
|
|
34
|
-
/**
|
|
37
|
+
/**
|
|
38
|
+
* Connectors used for linking accounts
|
|
39
|
+
* @default [new InjectedConnector()]
|
|
40
|
+
*/
|
|
35
41
|
connectors?: Connector[] | ((config: {
|
|
36
42
|
chainId?: number;
|
|
37
43
|
}) => Connector[]);
|
|
38
|
-
/**
|
|
44
|
+
/**
|
|
45
|
+
* Interface for connecting to network
|
|
46
|
+
* @default getDefaultProvider()
|
|
47
|
+
*/
|
|
39
48
|
provider?: BaseProvider | ((config: {
|
|
40
49
|
chainId?: number;
|
|
41
50
|
connector?: Connector;
|
|
@@ -46,6 +55,6 @@ export declare type Props = {
|
|
|
46
55
|
connector?: Connector;
|
|
47
56
|
}) => WebSocketProvider);
|
|
48
57
|
};
|
|
49
|
-
export declare const Provider: ({ autoConnect, children, connectors:
|
|
58
|
+
export declare const Provider: ({ autoConnect, children, connectors: connectors_, connectorStorageKey, provider: provider_, webSocketProvider: webSocketProvider_, }: React.PropsWithChildren<Props>) => React.FunctionComponentElement<React.ProviderProps<ContextValue | null>>;
|
|
50
59
|
export declare const useContext: () => ContextValue;
|
|
51
60
|
export {};
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import { BigNumber } from 'ethers';
|
|
2
2
|
import { Unit } from 'wagmi-private';
|
|
3
3
|
export declare type Config = {
|
|
4
|
-
|
|
4
|
+
/** Address or ENS name */
|
|
5
|
+
addressOrName?: string;
|
|
6
|
+
/** Units for formatting output */
|
|
5
7
|
formatUnits?: Unit | number;
|
|
8
|
+
/** Disables fetching */
|
|
6
9
|
skip?: boolean;
|
|
10
|
+
/** ERC-20 address */
|
|
7
11
|
token?: string;
|
|
12
|
+
/** Subscribe to changes */
|
|
8
13
|
watch?: boolean;
|
|
9
14
|
};
|
|
10
|
-
export declare const useBalance: ({
|
|
15
|
+
export declare const useBalance: ({ addressOrName, formatUnits, skip, token, watch, }?: Config) => readonly [{
|
|
11
16
|
readonly data: {
|
|
12
17
|
formatted: string;
|
|
13
18
|
symbol: string;
|
|
@@ -16,7 +21,7 @@ export declare const useBalance: ({ address, formatUnits, skip, token, watch, }?
|
|
|
16
21
|
readonly error: Error | undefined;
|
|
17
22
|
readonly loading: boolean | undefined;
|
|
18
23
|
}, (config?: {
|
|
19
|
-
|
|
24
|
+
addressOrName: string;
|
|
20
25
|
formatUnits?: Config['formatUnits'];
|
|
21
26
|
token?: Config['token'];
|
|
22
27
|
} | undefined) => Promise<Error | {
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
export { useContract } from './useContract';
|
|
2
2
|
export { useContractEvent } from './useContractEvent';
|
|
3
|
+
export { useContractRead } from './useContractRead';
|
|
4
|
+
export { useContractWrite as useContractWrite } from './useContractWrite';
|
|
3
5
|
export { useToken } from './useToken';
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { ContractInterface, Signer } from 'ethers';
|
|
2
2
|
import { Provider } from '@ethersproject/providers';
|
|
3
3
|
export declare type Config = {
|
|
4
|
+
/** Contract address or ENS name */
|
|
4
5
|
addressOrName: string;
|
|
6
|
+
/** Contract interface or ABI */
|
|
5
7
|
contractInterface: ContractInterface;
|
|
8
|
+
/** Signer or provider to attach to contract */
|
|
6
9
|
signerOrProvider?: Signer | Provider;
|
|
7
10
|
};
|
|
8
11
|
export declare const useContract: <Contract_1 = any>({ addressOrName, contractInterface, signerOrProvider, }: Config) => Contract_1;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ethers } from 'ethers';
|
|
2
2
|
import { Config as UseContractConfig } from './useContract';
|
|
3
3
|
declare type Config = {
|
|
4
|
+
/** Subscribe to changes */
|
|
4
5
|
watch?: boolean;
|
|
5
6
|
};
|
|
6
7
|
export declare const useContractEvent: <Contract extends ethers.Contract = ethers.Contract>(contractConfig: UseContractConfig, eventName: Parameters<Contract["on"]>[0], listener: Parameters<Contract["on"]>[1], { watch }?: Config) => void;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Overrides, ethers } from 'ethers';
|
|
2
|
+
import { Config as UseContractConfig } from './useContract';
|
|
3
|
+
declare type Config = {
|
|
4
|
+
args?: any | any[];
|
|
5
|
+
overrides?: Overrides;
|
|
6
|
+
skip?: boolean;
|
|
7
|
+
watch?: boolean;
|
|
8
|
+
};
|
|
9
|
+
export declare const useContractRead: <Contract extends ethers.Contract = ethers.Contract>(contractConfig: UseContractConfig, functionName: string, { args, overrides, skip, watch }?: Config) => readonly [{
|
|
10
|
+
readonly data: ethers.utils.Result | undefined;
|
|
11
|
+
readonly error: Error | undefined;
|
|
12
|
+
readonly loading: boolean | undefined;
|
|
13
|
+
}, (config?: {
|
|
14
|
+
args?: Config['args'];
|
|
15
|
+
overrides: Config['overrides'];
|
|
16
|
+
} | undefined) => Promise<any>];
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Overrides, ethers } from 'ethers';
|
|
2
|
+
import { Config as UseContractConfig } from './useContract';
|
|
3
|
+
declare type Config = {
|
|
4
|
+
args?: any | any[];
|
|
5
|
+
overrides?: Overrides;
|
|
6
|
+
};
|
|
7
|
+
export declare const useContractWrite: <Contract extends ethers.Contract = ethers.Contract>(contractConfig: UseContractConfig, functionName: string, { args, overrides }?: Config) => readonly [{
|
|
8
|
+
readonly data: ethers.providers.TransactionResponse | undefined;
|
|
9
|
+
readonly error: Error | undefined;
|
|
10
|
+
readonly loading: boolean | undefined;
|
|
11
|
+
}, (config?: {
|
|
12
|
+
args?: Config['args'];
|
|
13
|
+
overrides: Config['overrides'];
|
|
14
|
+
} | undefined) => Promise<any>];
|
|
15
|
+
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { useAccount, useBalance, useConnect, useNetwork, useSignMessage, } from './accounts';
|
|
2
|
-
export { useContract, useContractEvent, useToken } from './contracts';
|
|
2
|
+
export { useContract, useContractEvent, useContractRead, useContractWrite, useToken, } from './contracts';
|
|
3
3
|
export { useEnsAvatar, useEnsLookup, useEnsResolver } from './ens';
|
|
4
4
|
export { useBlockNumber, useFeeData } from './network-status';
|
|
5
5
|
export { useProvider, useWebSocketProvider } from './providers';
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { FeeData } from '@ethersproject/providers';
|
|
2
2
|
import { Unit } from 'wagmi-private';
|
|
3
3
|
declare type Config = {
|
|
4
|
+
/** Units for formatting output */
|
|
4
5
|
formatUnits?: Unit | number;
|
|
6
|
+
/** Disables fetching */
|
|
5
7
|
skip?: boolean;
|
|
8
|
+
/** Subscribe to changes */
|
|
6
9
|
watch?: boolean;
|
|
7
10
|
};
|
|
8
11
|
export declare const useFeeData: ({ formatUnits, skip, watch, }?: Config) => readonly [{
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { TransactionRequest, TransactionResponse } from '@ethersproject/providers';
|
|
2
2
|
export declare type Config = {
|
|
3
|
+
/** Object to use when creating transaction */
|
|
3
4
|
request?: TransactionRequest;
|
|
4
5
|
};
|
|
5
6
|
export declare const useTransaction: ({ request }?: Config) => readonly [{
|
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
import { TransactionReceipt, TransactionResponse } from '@ethersproject/providers';
|
|
2
2
|
export declare type Config = {
|
|
3
|
+
/**
|
|
4
|
+
* Number of blocks to wait for after transaction is mined
|
|
5
|
+
* @default 1
|
|
6
|
+
*/
|
|
3
7
|
confirmations?: number;
|
|
8
|
+
/** Transaction hash to monitor */
|
|
4
9
|
hash?: string;
|
|
10
|
+
/** Disables fetching */
|
|
5
11
|
skip?: boolean;
|
|
6
12
|
timeout?: number;
|
|
13
|
+
/** Function resolving to transaction receipt */
|
|
7
14
|
wait?: TransactionResponse['wait'];
|
|
8
15
|
};
|
|
9
|
-
export declare const useWaitForTransaction: ({ confirmations, hash, skip, timeout, wait:
|
|
16
|
+
export declare const useWaitForTransaction: ({ confirmations, hash, skip, timeout, wait: wait_, }?: Config) => readonly [{
|
|
10
17
|
readonly data: TransactionReceipt | undefined;
|
|
11
18
|
readonly error: Error | undefined;
|
|
12
19
|
readonly loading: boolean | undefined;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { Provider, useContext } from './context';
|
|
2
2
|
export type { Props as ProviderProps } from './context';
|
|
3
|
-
export { useAccount, useBalance, useBlockNumber, useConnect, useContract, useContractEvent, useEnsAvatar, useEnsLookup, useEnsResolver, useFeeData, useNetwork, useProvider, useSignMessage, useToken, useTransaction, useWaitForTransaction, useWebSocketProvider, } from './hooks';
|
|
3
|
+
export { useAccount, useBalance, useBlockNumber, useConnect, useContract, useContractEvent, useContractRead, useContractWrite, useEnsAvatar, useEnsLookup, useEnsResolver, useFeeData, useNetwork, useProvider, useSignMessage, useToken, useTransaction, useWaitForTransaction, useWebSocketProvider, } from './hooks';
|
|
4
4
|
export { Connector, InjectedConnector, WalletConnectConnector, WalletLinkConnector, chain, defaultChains, defaultL2Chains, developmentChains, erc1155ABI, erc20ABI, erc721ABI, normalizeChainId, } from 'wagmi-private';
|
|
5
5
|
export type { Chain, Data } from 'wagmi-private';
|