viem 0.3.1 → 0.3.2
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/dist/cjs/actions/ens/getEnsAddress.js.map +1 -1
- package/dist/cjs/actions/ens/getEnsAvatar.js.map +1 -1
- package/dist/cjs/actions/ens/getEnsName.js.map +1 -1
- package/dist/cjs/actions/ens/getEnsResolver.js.map +1 -1
- package/dist/cjs/actions/ens/getEnsText.js.map +1 -1
- package/dist/cjs/actions/getContract.js.map +1 -1
- package/dist/cjs/actions/public/estimateContractGas.js.map +1 -1
- package/dist/cjs/actions/public/getBalance.js.map +1 -1
- package/dist/cjs/actions/public/getFilterChanges.js.map +1 -1
- package/dist/cjs/actions/public/getFilterLogs.js.map +1 -1
- package/dist/cjs/actions/public/readContract.js.map +1 -1
- package/dist/cjs/actions/public/simulateContract.js.map +1 -1
- package/dist/cjs/actions/public/uninstallFilter.js.map +1 -1
- package/dist/cjs/actions/public/waitForTransactionReceipt.js.map +1 -1
- package/dist/cjs/actions/public/watchContractEvent.js.map +1 -1
- package/dist/cjs/actions/public/watchEvent.js.map +1 -1
- package/dist/cjs/actions/public/watchPendingTransactions.js.map +1 -1
- package/dist/cjs/actions/test/dropTransaction.js.map +1 -1
- package/dist/cjs/actions/test/getAutomine.js.map +1 -1
- package/dist/cjs/actions/test/getTxpoolContent.js.map +1 -1
- package/dist/cjs/actions/test/getTxpoolStatus.js.map +1 -1
- package/dist/cjs/actions/test/impersonateAccount.js.map +1 -1
- package/dist/cjs/actions/test/increaseTime.js.map +1 -1
- package/dist/cjs/actions/test/inspectTxpool.js.map +1 -1
- package/dist/cjs/actions/test/mine.js.map +1 -1
- package/dist/cjs/actions/test/removeBlockTimestampInterval.js.map +1 -1
- package/dist/cjs/actions/test/reset.js.map +1 -1
- package/dist/cjs/actions/test/revert.js.map +1 -1
- package/dist/cjs/actions/test/sendUnsignedTransaction.js.map +1 -1
- package/dist/cjs/actions/test/setAutomine.js.map +1 -1
- package/dist/cjs/actions/test/setBalance.js.map +1 -1
- package/dist/cjs/actions/test/setBlockGasLimit.js.map +1 -1
- package/dist/cjs/actions/test/setBlockTimestampInterval.js.map +1 -1
- package/dist/cjs/actions/test/setCode.js.map +1 -1
- package/dist/cjs/actions/test/setCoinbase.js.map +1 -1
- package/dist/cjs/actions/test/setIntervalMining.js.map +1 -1
- package/dist/cjs/actions/test/setLoggingEnabled.js.map +1 -1
- package/dist/cjs/actions/test/setMinGasPrice.js.map +1 -1
- package/dist/cjs/actions/test/setNextBlockBaseFeePerGas.js.map +1 -1
- package/dist/cjs/actions/test/setNextBlockTimestamp.js.map +1 -1
- package/dist/cjs/actions/test/setNonce.js.map +1 -1
- package/dist/cjs/actions/test/setRpcUrl.js.map +1 -1
- package/dist/cjs/actions/test/setStorageAt.js.map +1 -1
- package/dist/cjs/actions/test/snapshot.js.map +1 -1
- package/dist/cjs/actions/test/stopImpersonatingAccount.js.map +1 -1
- package/dist/cjs/actions/wallet/addChain.js.map +1 -1
- package/dist/cjs/actions/wallet/getAddresses.js.map +1 -1
- package/dist/cjs/actions/wallet/getPermissions.js.map +1 -1
- package/dist/cjs/actions/wallet/requestAddresses.js.map +1 -1
- package/dist/cjs/actions/wallet/requestPermissions.js.map +1 -1
- package/dist/cjs/actions/wallet/sendTransaction.js.map +1 -1
- package/dist/cjs/actions/wallet/signMessage.js.map +1 -1
- package/dist/cjs/actions/wallet/signTypedData.js.map +1 -1
- package/dist/cjs/actions/wallet/switchChain.js.map +1 -1
- package/dist/cjs/actions/wallet/watchAsset.js.map +1 -1
- package/dist/cjs/actions/wallet/writeContract.js.map +1 -1
- package/dist/cjs/clients/createPublicClient.js.map +1 -1
- package/dist/cjs/clients/createTestClient.js.map +1 -1
- package/dist/cjs/clients/createWalletClient.js.map +1 -1
- package/dist/cjs/clients/decorators/test.js.map +1 -1
- package/dist/cjs/clients/decorators/wallet.js.map +1 -1
- package/dist/cjs/errors/version.js +1 -1
- package/dist/cjs/utils/rpc.js +3 -6
- package/dist/cjs/utils/rpc.js.map +1 -1
- package/dist/esm/actions/ens/getEnsAddress.js.map +1 -1
- package/dist/esm/actions/ens/getEnsAvatar.js.map +1 -1
- package/dist/esm/actions/ens/getEnsName.js.map +1 -1
- package/dist/esm/actions/ens/getEnsResolver.js.map +1 -1
- package/dist/esm/actions/ens/getEnsText.js.map +1 -1
- package/dist/esm/actions/getContract.js.map +1 -1
- package/dist/esm/actions/public/estimateContractGas.js.map +1 -1
- package/dist/esm/actions/public/getBalance.js.map +1 -1
- package/dist/esm/actions/public/getFilterChanges.js.map +1 -1
- package/dist/esm/actions/public/getFilterLogs.js.map +1 -1
- package/dist/esm/actions/public/readContract.js.map +1 -1
- package/dist/esm/actions/public/simulateContract.js.map +1 -1
- package/dist/esm/actions/public/uninstallFilter.js.map +1 -1
- package/dist/esm/actions/public/waitForTransactionReceipt.js.map +1 -1
- package/dist/esm/actions/public/watchContractEvent.js.map +1 -1
- package/dist/esm/actions/public/watchEvent.js.map +1 -1
- package/dist/esm/actions/public/watchPendingTransactions.js.map +1 -1
- package/dist/esm/actions/test/dropTransaction.js.map +1 -1
- package/dist/esm/actions/test/getAutomine.js.map +1 -1
- package/dist/esm/actions/test/getTxpoolContent.js.map +1 -1
- package/dist/esm/actions/test/getTxpoolStatus.js.map +1 -1
- package/dist/esm/actions/test/impersonateAccount.js.map +1 -1
- package/dist/esm/actions/test/increaseTime.js.map +1 -1
- package/dist/esm/actions/test/inspectTxpool.js.map +1 -1
- package/dist/esm/actions/test/mine.js.map +1 -1
- package/dist/esm/actions/test/removeBlockTimestampInterval.js.map +1 -1
- package/dist/esm/actions/test/reset.js.map +1 -1
- package/dist/esm/actions/test/revert.js.map +1 -1
- package/dist/esm/actions/test/sendUnsignedTransaction.js.map +1 -1
- package/dist/esm/actions/test/setAutomine.js.map +1 -1
- package/dist/esm/actions/test/setBalance.js.map +1 -1
- package/dist/esm/actions/test/setBlockGasLimit.js.map +1 -1
- package/dist/esm/actions/test/setBlockTimestampInterval.js.map +1 -1
- package/dist/esm/actions/test/setCode.js.map +1 -1
- package/dist/esm/actions/test/setCoinbase.js.map +1 -1
- package/dist/esm/actions/test/setIntervalMining.js.map +1 -1
- package/dist/esm/actions/test/setLoggingEnabled.js.map +1 -1
- package/dist/esm/actions/test/setMinGasPrice.js.map +1 -1
- package/dist/esm/actions/test/setNextBlockBaseFeePerGas.js.map +1 -1
- package/dist/esm/actions/test/setNextBlockTimestamp.js.map +1 -1
- package/dist/esm/actions/test/setNonce.js.map +1 -1
- package/dist/esm/actions/test/setRpcUrl.js.map +1 -1
- package/dist/esm/actions/test/setStorageAt.js.map +1 -1
- package/dist/esm/actions/test/snapshot.js.map +1 -1
- package/dist/esm/actions/test/stopImpersonatingAccount.js.map +1 -1
- package/dist/esm/actions/wallet/addChain.js.map +1 -1
- package/dist/esm/actions/wallet/getAddresses.js.map +1 -1
- package/dist/esm/actions/wallet/getPermissions.js.map +1 -1
- package/dist/esm/actions/wallet/requestAddresses.js.map +1 -1
- package/dist/esm/actions/wallet/requestPermissions.js.map +1 -1
- package/dist/esm/actions/wallet/sendTransaction.js.map +1 -1
- package/dist/esm/actions/wallet/signMessage.js.map +1 -1
- package/dist/esm/actions/wallet/signTypedData.js.map +1 -1
- package/dist/esm/actions/wallet/switchChain.js.map +1 -1
- package/dist/esm/actions/wallet/watchAsset.js.map +1 -1
- package/dist/esm/actions/wallet/writeContract.js.map +1 -1
- package/dist/esm/clients/createPublicClient.js.map +1 -1
- package/dist/esm/clients/createTestClient.js.map +1 -1
- package/dist/esm/clients/createWalletClient.js.map +1 -1
- package/dist/esm/clients/decorators/test.js.map +1 -1
- package/dist/esm/clients/decorators/wallet.js.map +1 -1
- package/dist/esm/errors/version.js +1 -1
- package/dist/esm/utils/rpc.js +1 -1
- package/dist/esm/utils/rpc.js.map +1 -1
- package/dist/types/actions/ens/getEnsAddress.d.ts +0 -1
- package/dist/types/actions/ens/getEnsAddress.d.ts.map +1 -1
- package/dist/types/actions/ens/getEnsAvatar.d.ts +0 -1
- package/dist/types/actions/ens/getEnsAvatar.d.ts.map +1 -1
- package/dist/types/actions/ens/getEnsName.d.ts +0 -1
- package/dist/types/actions/ens/getEnsName.d.ts.map +1 -1
- package/dist/types/actions/ens/getEnsResolver.d.ts +0 -1
- package/dist/types/actions/ens/getEnsResolver.d.ts.map +1 -1
- package/dist/types/actions/ens/getEnsText.d.ts +0 -1
- package/dist/types/actions/ens/getEnsText.d.ts.map +1 -1
- package/dist/types/actions/getContract.d.ts +104 -2
- package/dist/types/actions/getContract.d.ts.map +1 -1
- package/dist/types/actions/public/estimateContractGas.d.ts +0 -1
- package/dist/types/actions/public/estimateContractGas.d.ts.map +1 -1
- package/dist/types/actions/public/getBalance.d.ts +0 -1
- package/dist/types/actions/public/getBalance.d.ts.map +1 -1
- package/dist/types/actions/public/getFilterChanges.d.ts +0 -1
- package/dist/types/actions/public/getFilterChanges.d.ts.map +1 -1
- package/dist/types/actions/public/getFilterLogs.d.ts +0 -1
- package/dist/types/actions/public/getFilterLogs.d.ts.map +1 -1
- package/dist/types/actions/public/readContract.d.ts +2 -3
- package/dist/types/actions/public/readContract.d.ts.map +1 -1
- package/dist/types/actions/public/simulateContract.d.ts +1 -2
- package/dist/types/actions/public/simulateContract.d.ts.map +1 -1
- package/dist/types/actions/public/uninstallFilter.d.ts +0 -1
- package/dist/types/actions/public/uninstallFilter.d.ts.map +1 -1
- package/dist/types/actions/public/waitForTransactionReceipt.d.ts +0 -1
- package/dist/types/actions/public/waitForTransactionReceipt.d.ts.map +1 -1
- package/dist/types/actions/public/watchContractEvent.d.ts +0 -1
- package/dist/types/actions/public/watchContractEvent.d.ts.map +1 -1
- package/dist/types/actions/public/watchEvent.d.ts +0 -1
- package/dist/types/actions/public/watchEvent.d.ts.map +1 -1
- package/dist/types/actions/public/watchPendingTransactions.d.ts +0 -1
- package/dist/types/actions/public/watchPendingTransactions.d.ts.map +1 -1
- package/dist/types/actions/test/dropTransaction.d.ts +22 -0
- package/dist/types/actions/test/dropTransaction.d.ts.map +1 -1
- package/dist/types/actions/test/getAutomine.d.ts +20 -0
- package/dist/types/actions/test/getAutomine.d.ts.map +1 -1
- package/dist/types/actions/test/getTxpoolContent.d.ts +22 -0
- package/dist/types/actions/test/getTxpoolContent.d.ts.map +1 -1
- package/dist/types/actions/test/getTxpoolStatus.d.ts +20 -0
- package/dist/types/actions/test/getTxpoolStatus.d.ts.map +1 -1
- package/dist/types/actions/test/impersonateAccount.d.ts +22 -0
- package/dist/types/actions/test/impersonateAccount.d.ts.map +1 -1
- package/dist/types/actions/test/increaseTime.d.ts +22 -0
- package/dist/types/actions/test/increaseTime.d.ts.map +1 -1
- package/dist/types/actions/test/inspectTxpool.d.ts +20 -0
- package/dist/types/actions/test/inspectTxpool.d.ts.map +1 -1
- package/dist/types/actions/test/mine.d.ts +20 -0
- package/dist/types/actions/test/mine.d.ts.map +1 -1
- package/dist/types/actions/test/removeBlockTimestampInterval.d.ts +19 -0
- package/dist/types/actions/test/removeBlockTimestampInterval.d.ts.map +1 -1
- package/dist/types/actions/test/reset.d.ts +20 -0
- package/dist/types/actions/test/reset.d.ts.map +1 -1
- package/dist/types/actions/test/revert.d.ts +20 -0
- package/dist/types/actions/test/revert.d.ts.map +1 -1
- package/dist/types/actions/test/sendUnsignedTransaction.d.ts +25 -0
- package/dist/types/actions/test/sendUnsignedTransaction.d.ts.map +1 -1
- package/dist/types/actions/test/setAutomine.d.ts +19 -0
- package/dist/types/actions/test/setAutomine.d.ts.map +1 -1
- package/dist/types/actions/test/setBalance.d.ts +23 -0
- package/dist/types/actions/test/setBalance.d.ts.map +1 -1
- package/dist/types/actions/test/setBlockGasLimit.d.ts +20 -0
- package/dist/types/actions/test/setBlockGasLimit.d.ts.map +1 -1
- package/dist/types/actions/test/setBlockTimestampInterval.d.ts +20 -0
- package/dist/types/actions/test/setBlockTimestampInterval.d.ts.map +1 -1
- package/dist/types/actions/test/setCode.d.ts +23 -0
- package/dist/types/actions/test/setCode.d.ts.map +1 -1
- package/dist/types/actions/test/setCoinbase.d.ts +22 -0
- package/dist/types/actions/test/setCoinbase.d.ts.map +1 -1
- package/dist/types/actions/test/setIntervalMining.d.ts +20 -0
- package/dist/types/actions/test/setIntervalMining.d.ts.map +1 -1
- package/dist/types/actions/test/setLoggingEnabled.d.ts +19 -0
- package/dist/types/actions/test/setLoggingEnabled.d.ts.map +1 -1
- package/dist/types/actions/test/setMinGasPrice.d.ts +24 -0
- package/dist/types/actions/test/setMinGasPrice.d.ts.map +1 -1
- package/dist/types/actions/test/setNextBlockBaseFeePerGas.d.ts +22 -0
- package/dist/types/actions/test/setNextBlockBaseFeePerGas.d.ts.map +1 -1
- package/dist/types/actions/test/setNextBlockTimestamp.d.ts +20 -0
- package/dist/types/actions/test/setNextBlockTimestamp.d.ts.map +1 -1
- package/dist/types/actions/test/setNonce.d.ts +23 -0
- package/dist/types/actions/test/setNonce.d.ts.map +1 -1
- package/dist/types/actions/test/setRpcUrl.d.ts +20 -0
- package/dist/types/actions/test/setRpcUrl.d.ts.map +1 -1
- package/dist/types/actions/test/setStorageAt.d.ts +24 -0
- package/dist/types/actions/test/setStorageAt.d.ts.map +1 -1
- package/dist/types/actions/test/snapshot.d.ts +19 -0
- package/dist/types/actions/test/snapshot.d.ts.map +1 -1
- package/dist/types/actions/test/stopImpersonatingAccount.d.ts +22 -0
- package/dist/types/actions/test/stopImpersonatingAccount.d.ts.map +1 -1
- package/dist/types/actions/wallet/addChain.d.ts +20 -0
- package/dist/types/actions/wallet/addChain.d.ts.map +1 -1
- package/dist/types/actions/wallet/deployContract.d.ts +1 -1
- package/dist/types/actions/wallet/getAddresses.d.ts +20 -0
- package/dist/types/actions/wallet/getAddresses.d.ts.map +1 -1
- package/dist/types/actions/wallet/getPermissions.d.ts +20 -0
- package/dist/types/actions/wallet/getPermissions.d.ts.map +1 -1
- package/dist/types/actions/wallet/requestAddresses.d.ts +24 -0
- package/dist/types/actions/wallet/requestAddresses.d.ts.map +1 -1
- package/dist/types/actions/wallet/requestPermissions.d.ts +26 -3
- package/dist/types/actions/wallet/requestPermissions.d.ts.map +1 -1
- package/dist/types/actions/wallet/sendTransaction.d.ts +45 -0
- package/dist/types/actions/wallet/sendTransaction.d.ts.map +1 -1
- package/dist/types/actions/wallet/signMessage.d.ts +46 -0
- package/dist/types/actions/wallet/signMessage.d.ts.map +1 -1
- package/dist/types/actions/wallet/signTypedData.d.ts +98 -0
- package/dist/types/actions/wallet/signTypedData.d.ts.map +1 -1
- package/dist/types/actions/wallet/switchChain.d.ts +21 -0
- package/dist/types/actions/wallet/switchChain.d.ts.map +1 -1
- package/dist/types/actions/wallet/watchAsset.d.ts +28 -0
- package/dist/types/actions/wallet/watchAsset.d.ts.map +1 -1
- package/dist/types/actions/wallet/writeContract.d.ts +50 -0
- package/dist/types/actions/wallet/writeContract.d.ts.map +1 -1
- package/dist/types/clients/createPublicClient.d.ts +17 -1
- package/dist/types/clients/createPublicClient.d.ts.map +1 -1
- package/dist/types/clients/createTestClient.d.ts +20 -0
- package/dist/types/clients/createTestClient.d.ts.map +1 -1
- package/dist/types/clients/createWalletClient.d.ts +34 -1
- package/dist/types/clients/createWalletClient.d.ts.map +1 -1
- package/dist/types/clients/decorators/public.d.ts +37 -37
- package/dist/types/clients/decorators/test.d.ts +536 -0
- package/dist/types/clients/decorators/test.d.ts.map +1 -1
- package/dist/types/clients/decorators/wallet.d.ts +389 -2
- package/dist/types/clients/decorators/wallet.d.ts.map +1 -1
- package/dist/types/errors/version.d.ts +1 -1
- package/dist/types/utils/rpc.d.ts +1 -1
- package/dist/types/utils/rpc.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/actions/ens/getEnsAddress.ts +0 -1
- package/src/actions/ens/getEnsAvatar.ts +0 -1
- package/src/actions/ens/getEnsName.ts +0 -1
- package/src/actions/ens/getEnsResolver.ts +0 -1
- package/src/actions/ens/getEnsText.ts +0 -1
- package/src/actions/getContract.ts +104 -2
- package/src/actions/public/estimateContractGas.ts +0 -1
- package/src/actions/public/getBalance.ts +0 -1
- package/src/actions/public/getFilterChanges.ts +0 -1
- package/src/actions/public/getFilterLogs.ts +0 -1
- package/src/actions/public/readContract.ts +2 -3
- package/src/actions/public/simulateContract.ts +1 -2
- package/src/actions/public/uninstallFilter.ts +0 -1
- package/src/actions/public/waitForTransactionReceipt.ts +0 -1
- package/src/actions/public/watchContractEvent.ts +0 -1
- package/src/actions/public/watchEvent.ts +0 -1
- package/src/actions/public/watchPendingTransactions.ts +0 -1
- package/src/actions/test/dropTransaction.ts +22 -0
- package/src/actions/test/getAutomine.ts +20 -0
- package/src/actions/test/getTxpoolContent.ts +22 -0
- package/src/actions/test/getTxpoolStatus.ts +20 -0
- package/src/actions/test/impersonateAccount.ts +22 -0
- package/src/actions/test/increaseTime.ts +22 -0
- package/src/actions/test/inspectTxpool.ts +20 -0
- package/src/actions/test/mine.ts +20 -0
- package/src/actions/test/removeBlockTimestampInterval.ts +19 -0
- package/src/actions/test/reset.ts +20 -0
- package/src/actions/test/revert.ts +20 -0
- package/src/actions/test/sendUnsignedTransaction.ts +25 -0
- package/src/actions/test/setAutomine.ts +19 -0
- package/src/actions/test/setBalance.ts +23 -0
- package/src/actions/test/setBlockGasLimit.ts +20 -0
- package/src/actions/test/setBlockTimestampInterval.ts +20 -0
- package/src/actions/test/setCode.ts +23 -0
- package/src/actions/test/setCoinbase.ts +22 -0
- package/src/actions/test/setIntervalMining.ts +20 -0
- package/src/actions/test/setLoggingEnabled.ts +19 -0
- package/src/actions/test/setMinGasPrice.ts +24 -0
- package/src/actions/test/setNextBlockBaseFeePerGas.ts +22 -0
- package/src/actions/test/setNextBlockTimestamp.ts +20 -0
- package/src/actions/test/setNonce.ts +23 -0
- package/src/actions/test/setRpcUrl.ts +20 -0
- package/src/actions/test/setStorageAt.ts +24 -0
- package/src/actions/test/snapshot.ts +19 -0
- package/src/actions/test/stopImpersonatingAccount.ts +22 -0
- package/src/actions/wallet/addChain.ts +20 -0
- package/src/actions/wallet/deployContract.ts +1 -1
- package/src/actions/wallet/getAddresses.ts +20 -0
- package/src/actions/wallet/getPermissions.ts +20 -0
- package/src/actions/wallet/requestAddresses.ts +24 -0
- package/src/actions/wallet/requestPermissions.ts +31 -6
- package/src/actions/wallet/sendTransaction.ts +45 -0
- package/src/actions/wallet/signMessage.ts +46 -0
- package/src/actions/wallet/signTypedData.ts +98 -0
- package/src/actions/wallet/switchChain.ts +24 -1
- package/src/actions/wallet/watchAsset.ts +28 -0
- package/src/actions/wallet/writeContract.ts +50 -0
- package/src/clients/createPublicClient.ts +17 -1
- package/src/clients/createTestClient.ts +20 -0
- package/src/clients/createWalletClient.ts +34 -1
- package/src/clients/decorators/public.ts +37 -37
- package/src/clients/decorators/test.ts +536 -0
- package/src/clients/decorators/wallet.ts +389 -2
- package/src/errors/version.ts +1 -1
- package/src/utils/rpc.ts +2 -2
@@ -44,6 +44,23 @@ export type WalletActions<
|
|
44
44
|
TChain extends Chain | undefined = Chain | undefined,
|
45
45
|
TAccount extends Account | undefined = Account | undefined,
|
46
46
|
> = {
|
47
|
+
/**
|
48
|
+
* Adds an EVM chain to the wallet.
|
49
|
+
*
|
50
|
+
* - Docs: https://viem.sh/docs/actions/wallet/addChain.html
|
51
|
+
* - JSON-RPC Methods: [`eth_addEthereumChain`](https://eips.ethereum.org/EIPS/eip-3085)
|
52
|
+
*
|
53
|
+
* @param args - {@link AddChainParameters}
|
54
|
+
*
|
55
|
+
* @example
|
56
|
+
* import { createWalletClient, custom } from 'viem'
|
57
|
+
* import { optimism } from 'viem/chains'
|
58
|
+
*
|
59
|
+
* const client = createWalletClient({
|
60
|
+
* transport: custom(window.ethereum),
|
61
|
+
* })
|
62
|
+
* await client.addChain({ chain: optimism })
|
63
|
+
*/
|
47
64
|
addChain: (args: AddChainParameters) => Promise<void>
|
48
65
|
/**
|
49
66
|
* Deploys a contract to the network, given bytecode and constructor arguments.
|
@@ -51,7 +68,7 @@ export type WalletActions<
|
|
51
68
|
* - Docs: https://viem.sh/docs/contract/deployContract.html
|
52
69
|
* - Examples: https://stackblitz.com/github/wagmi-dev/viem/tree/main/examples/contracts/deploying-contracts
|
53
70
|
*
|
54
|
-
* @param
|
71
|
+
* @param args - {@link DeployContractParameters}
|
55
72
|
* @returns The [Transaction](https://viem.sh/docs/glossary/terms#transaction) hash. {@link DeployContractReturnType}
|
56
73
|
*
|
57
74
|
* @example
|
@@ -60,7 +77,7 @@ export type WalletActions<
|
|
60
77
|
* import { mainnet } from 'viem/chains'
|
61
78
|
*
|
62
79
|
* const client = createWalletClient({
|
63
|
-
* account
|
80
|
+
* account: privateKeyToAccount('0x…'),
|
64
81
|
* chain: mainnet,
|
65
82
|
* transport: http(),
|
66
83
|
* })
|
@@ -76,27 +93,397 @@ export type WalletActions<
|
|
76
93
|
>(
|
77
94
|
args: DeployContractParameters<TAbi, TChain, TAccount, TChainOverride>,
|
78
95
|
) => Promise<DeployContractReturnType>
|
96
|
+
/**
|
97
|
+
* Returns a list of account addresses owned by the wallet or client.
|
98
|
+
*
|
99
|
+
* - Docs: https://viem.sh/docs/actions/wallet/getAddresses.html
|
100
|
+
* - JSON-RPC Methods: [`eth_accounts`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_accounts)
|
101
|
+
*
|
102
|
+
* @returns List of account addresses owned by the wallet or client. {@link GetAddressesReturnType}
|
103
|
+
*
|
104
|
+
* @example
|
105
|
+
* import { createWalletClient, custom } from 'viem'
|
106
|
+
* import { mainnet } from 'viem/chains'
|
107
|
+
*
|
108
|
+
* const client = createWalletClient({
|
109
|
+
* chain: mainnet,
|
110
|
+
* transport: custom(window.ethereum),
|
111
|
+
* })
|
112
|
+
* const accounts = await client.getAddresses()
|
113
|
+
*/
|
79
114
|
getAddresses: () => Promise<GetAddressesReturnType>
|
115
|
+
/**
|
116
|
+
* Returns the chain ID associated with the current network.
|
117
|
+
*
|
118
|
+
* - Docs: https://viem.sh/docs/actions/public/getChainId.html
|
119
|
+
* - JSON-RPC Methods: [`eth_chainId`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_chainid)
|
120
|
+
*
|
121
|
+
* @returns The current chain ID. {@link GetChainIdReturnType}
|
122
|
+
*
|
123
|
+
* @example
|
124
|
+
* import { createWalletClient, http } from 'viem'
|
125
|
+
* import { mainnet } from 'viem/chains'
|
126
|
+
*
|
127
|
+
* const client = createWalletClient({
|
128
|
+
* chain: mainnet,
|
129
|
+
* transport: custom(window.ethereum),
|
130
|
+
* })
|
131
|
+
* const chainId = await client.getChainId()
|
132
|
+
* // 1
|
133
|
+
*/
|
80
134
|
getChainId: () => Promise<GetChainIdReturnType>
|
135
|
+
/**
|
136
|
+
* Gets the wallets current permissions.
|
137
|
+
*
|
138
|
+
* - Docs: https://viem.sh/docs/actions/wallet/getPermissions.html
|
139
|
+
* - JSON-RPC Methods: [`wallet_getPermissions`](https://eips.ethereum.org/EIPS/eip-2255)
|
140
|
+
*
|
141
|
+
* @returns The wallet permissions. {@link GetPermissionsReturnType}
|
142
|
+
*
|
143
|
+
* @example
|
144
|
+
* import { createWalletClient, custom } from 'viem'
|
145
|
+
* import { mainnet } from 'viem/chains'
|
146
|
+
*
|
147
|
+
* const client = createWalletClient({
|
148
|
+
* chain: mainnet,
|
149
|
+
* transport: custom(window.ethereum),
|
150
|
+
* })
|
151
|
+
* const permissions = await client.getPermissions()
|
152
|
+
*/
|
81
153
|
getPermissions: () => Promise<GetPermissionsReturnType>
|
154
|
+
/**
|
155
|
+
* Requests a list of accounts managed by a wallet.
|
156
|
+
*
|
157
|
+
* - Docs: https://viem.sh/docs/actions/wallet/requestAddresses.html
|
158
|
+
* - JSON-RPC Methods: [`eth_requestAccounts`](https://eips.ethereum.org/EIPS/eip-1102)
|
159
|
+
*
|
160
|
+
* Sends a request to the wallet, asking for permission to access the user's accounts. After the user accepts the request, it will return a list of accounts (addresses).
|
161
|
+
*
|
162
|
+
* This API can be useful for dapps that need to access the user's accounts in order to execute transactions or interact with smart contracts.
|
163
|
+
*
|
164
|
+
* @returns List of accounts managed by a wallet {@link RequestAddressesReturnType}
|
165
|
+
*
|
166
|
+
* @example
|
167
|
+
* import { createWalletClient, custom } from 'viem'
|
168
|
+
* import { mainnet } from 'viem/chains'
|
169
|
+
*
|
170
|
+
* const client = createWalletClient({
|
171
|
+
* chain: mainnet,
|
172
|
+
* transport: custom(window.ethereum),
|
173
|
+
* })
|
174
|
+
* const accounts = await client.requestAddresses()
|
175
|
+
*/
|
82
176
|
requestAddresses: () => Promise<RequestAddressesReturnType>
|
177
|
+
/**
|
178
|
+
* Requests permissions for a wallet.
|
179
|
+
*
|
180
|
+
* - Docs: https://viem.sh/docs/actions/wallet/requestPermissions.html
|
181
|
+
* - JSON-RPC Methods: [`wallet_requestPermissions`](https://eips.ethereum.org/EIPS/eip-2255)
|
182
|
+
*
|
183
|
+
* @param args - {@link RequestPermissionsParameters}
|
184
|
+
* @returns The wallet permissions. {@link RequestPermissionsReturnType}
|
185
|
+
*
|
186
|
+
* @example
|
187
|
+
* import { createWalletClient, custom } from 'viem'
|
188
|
+
* import { mainnet } from 'viem/chains'
|
189
|
+
*
|
190
|
+
* const client = createWalletClient({
|
191
|
+
* chain: mainnet,
|
192
|
+
* transport: custom(window.ethereum),
|
193
|
+
* })
|
194
|
+
* const permissions = await client.requestPermissions({
|
195
|
+
* eth_accounts: {}
|
196
|
+
* })
|
197
|
+
*/
|
83
198
|
requestPermissions: (
|
84
199
|
args: RequestPermissionsParameters,
|
85
200
|
) => Promise<RequestPermissionsReturnType>
|
201
|
+
/**
|
202
|
+
* Creates, signs, and sends a new transaction to the network.
|
203
|
+
*
|
204
|
+
* - Docs: https://viem.sh/docs/actions/wallet/sendTransaction.html
|
205
|
+
* - Examples: https://stackblitz.com/github/wagmi-dev/viem/tree/main/examples/transactions/sending-transactions
|
206
|
+
* - JSON-RPC Methods:
|
207
|
+
* - JSON-RPC Accounts: [`eth_sendTransaction`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_sendtransaction)
|
208
|
+
* - Local Accounts: [`eth_sendRawTransaction`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_sendrawtransaction)
|
209
|
+
*
|
210
|
+
* @param args - {@link SendTransactionParameters}
|
211
|
+
* @returns The [Transaction](https://viem.sh/docs/glossary/terms.html#transaction) hash. {@link SendTransactionReturnType}
|
212
|
+
*
|
213
|
+
* @example
|
214
|
+
* import { createWalletClient, custom } from 'viem'
|
215
|
+
* import { mainnet } from 'viem/chains'
|
216
|
+
*
|
217
|
+
* const client = createWalletClient({
|
218
|
+
* chain: mainnet,
|
219
|
+
* transport: custom(window.ethereum),
|
220
|
+
* })
|
221
|
+
* const hash = await client.sendTransaction({
|
222
|
+
* account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
|
223
|
+
* to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
|
224
|
+
* value: 1000000000000000000n,
|
225
|
+
* })
|
226
|
+
*
|
227
|
+
* @example
|
228
|
+
* // Account Hoisting
|
229
|
+
* import { createWalletClient, http } from 'viem'
|
230
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
231
|
+
* import { mainnet } from 'viem/chains'
|
232
|
+
*
|
233
|
+
* const client = createWalletClient({
|
234
|
+
* account: privateKeyToAccount('0x…'),
|
235
|
+
* chain: mainnet,
|
236
|
+
* transport: http(),
|
237
|
+
* })
|
238
|
+
* const hash = await client.sendTransaction({
|
239
|
+
* to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
|
240
|
+
* value: 1000000000000000000n,
|
241
|
+
* })
|
242
|
+
*/
|
86
243
|
sendTransaction: <TChainOverride extends Chain | undefined>(
|
87
244
|
args: SendTransactionParameters<TChain, TAccount, TChainOverride>,
|
88
245
|
) => Promise<SendTransactionReturnType>
|
246
|
+
/**
|
247
|
+
* Calculates an Ethereum-specific signature in [EIP-191 format](https://eips.ethereum.org/EIPS/eip-191): `keccak256("\x19Ethereum Signed Message:\n" + len(message) + message))`.
|
248
|
+
*
|
249
|
+
* - Docs: https://viem.sh/docs/actions/wallet/signMessage.html
|
250
|
+
* - JSON-RPC Methods:
|
251
|
+
* - JSON-RPC Accounts: [`personal_sign`](https://docs.metamask.io/guide/signing-data.html#personal-sign)
|
252
|
+
* - Local Accounts: Signs locally. No JSON-RPC request.
|
253
|
+
*
|
254
|
+
* With the calculated signature, you can:
|
255
|
+
* - use [`verifyMessage`](https://viem.sh/docs/utilities/verifyMessage) to verify the signature,
|
256
|
+
* - use [`recoverMessageAddress`](https://viem.sh/docs/utilities/recoverMessageAddress) to recover the signing address from a signature.
|
257
|
+
*
|
258
|
+
* @param args - {@link SignMessageParameters}
|
259
|
+
* @returns The signed message. {@link SignMessageReturnType}
|
260
|
+
*
|
261
|
+
* @example
|
262
|
+
* import { createWalletClient, custom } from 'viem'
|
263
|
+
* import { mainnet } from 'viem/chains'
|
264
|
+
*
|
265
|
+
* const client = createWalletClient({
|
266
|
+
* chain: mainnet,
|
267
|
+
* transport: custom(window.ethereum),
|
268
|
+
* })
|
269
|
+
* const signature = await client.signMessage({
|
270
|
+
* account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
|
271
|
+
* message: 'hello world',
|
272
|
+
* })
|
273
|
+
*
|
274
|
+
* @example
|
275
|
+
* // Account Hoisting
|
276
|
+
* import { createWalletClient, http } from 'viem'
|
277
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
278
|
+
* import { mainnet } from 'viem/chains'
|
279
|
+
*
|
280
|
+
* const client = createWalletClient({
|
281
|
+
* account: privateKeyToAccount('0x…'),
|
282
|
+
* chain: mainnet,
|
283
|
+
* transport: http(),
|
284
|
+
* })
|
285
|
+
* const signature = await client.signMessage({
|
286
|
+
* message: 'hello world',
|
287
|
+
* })
|
288
|
+
*/
|
89
289
|
signMessage: (
|
90
290
|
args: SignMessageParameters<TAccount>,
|
91
291
|
) => Promise<SignMessageReturnType>
|
292
|
+
/**
|
293
|
+
* Signs typed data and calculates an Ethereum-specific signature in [EIP-191 format](https://eips.ethereum.org/EIPS/eip-191): `keccak256("\x19Ethereum Signed Message:\n" + len(message) + message))`.
|
294
|
+
*
|
295
|
+
* - Docs: https://viem.sh/docs/actions/wallet/signTypedData.html
|
296
|
+
* - JSON-RPC Methods:
|
297
|
+
* - JSON-RPC Accounts: [`eth_signTypedData_v4`](https://docs.metamask.io/guide/signing-data.html#signtypeddata-v4)
|
298
|
+
* - Local Accounts: Signs locally. No JSON-RPC request.
|
299
|
+
*
|
300
|
+
* @param client - Client to use
|
301
|
+
* @param args - {@link SignTypedDataParameters}
|
302
|
+
* @returns The signed data. {@link SignTypedDataReturnType}
|
303
|
+
*
|
304
|
+
* @example
|
305
|
+
* import { createWalletClient, custom } from 'viem'
|
306
|
+
* import { mainnet } from 'viem/chains'
|
307
|
+
*
|
308
|
+
* const client = createWalletClient({
|
309
|
+
* chain: mainnet,
|
310
|
+
* transport: custom(window.ethereum),
|
311
|
+
* })
|
312
|
+
* const signature = await client.signTypedData({
|
313
|
+
* account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
|
314
|
+
* domain: {
|
315
|
+
* name: 'Ether Mail',
|
316
|
+
* version: '1',
|
317
|
+
* chainId: 1,
|
318
|
+
* verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC',
|
319
|
+
* },
|
320
|
+
* types: {
|
321
|
+
* Person: [
|
322
|
+
* { name: 'name', type: 'string' },
|
323
|
+
* { name: 'wallet', type: 'address' },
|
324
|
+
* ],
|
325
|
+
* Mail: [
|
326
|
+
* { name: 'from', type: 'Person' },
|
327
|
+
* { name: 'to', type: 'Person' },
|
328
|
+
* { name: 'contents', type: 'string' },
|
329
|
+
* ],
|
330
|
+
* },
|
331
|
+
* primaryType: 'Mail',
|
332
|
+
* message: {
|
333
|
+
* from: {
|
334
|
+
* name: 'Cow',
|
335
|
+
* wallet: '0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826',
|
336
|
+
* },
|
337
|
+
* to: {
|
338
|
+
* name: 'Bob',
|
339
|
+
* wallet: '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB',
|
340
|
+
* },
|
341
|
+
* contents: 'Hello, Bob!',
|
342
|
+
* },
|
343
|
+
* })
|
344
|
+
*
|
345
|
+
* @example
|
346
|
+
* // Account Hoisting
|
347
|
+
* import { createWalletClient, http } from 'viem'
|
348
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
349
|
+
* import { mainnet } from 'viem/chains'
|
350
|
+
*
|
351
|
+
* const client = createWalletClient({
|
352
|
+
* account: privateKeyToAccount('0x…'),
|
353
|
+
* chain: mainnet,
|
354
|
+
* transport: http(),
|
355
|
+
* })
|
356
|
+
* const signature = await client.signTypedData({
|
357
|
+
* domain: {
|
358
|
+
* name: 'Ether Mail',
|
359
|
+
* version: '1',
|
360
|
+
* chainId: 1,
|
361
|
+
* verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC',
|
362
|
+
* },
|
363
|
+
* types: {
|
364
|
+
* Person: [
|
365
|
+
* { name: 'name', type: 'string' },
|
366
|
+
* { name: 'wallet', type: 'address' },
|
367
|
+
* ],
|
368
|
+
* Mail: [
|
369
|
+
* { name: 'from', type: 'Person' },
|
370
|
+
* { name: 'to', type: 'Person' },
|
371
|
+
* { name: 'contents', type: 'string' },
|
372
|
+
* ],
|
373
|
+
* },
|
374
|
+
* primaryType: 'Mail',
|
375
|
+
* message: {
|
376
|
+
* from: {
|
377
|
+
* name: 'Cow',
|
378
|
+
* wallet: '0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826',
|
379
|
+
* },
|
380
|
+
* to: {
|
381
|
+
* name: 'Bob',
|
382
|
+
* wallet: '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB',
|
383
|
+
* },
|
384
|
+
* contents: 'Hello, Bob!',
|
385
|
+
* },
|
386
|
+
* })
|
387
|
+
*/
|
92
388
|
signTypedData: <
|
93
389
|
TTypedData extends TypedData | { [key: string]: unknown },
|
94
390
|
TPrimaryType extends string,
|
95
391
|
>(
|
96
392
|
args: SignTypedDataParameters<TTypedData, TPrimaryType, TAccount>,
|
97
393
|
) => Promise<SignTypedDataReturnType>
|
394
|
+
/**
|
395
|
+
* Switch the target chain in a wallet.
|
396
|
+
*
|
397
|
+
* - Docs: https://viem.sh/docs/actions/wallet/switchChain.html
|
398
|
+
* - JSON-RPC Methods: [`eth_switchEthereumChain`](https://eips.ethereum.org/EIPS/eip-3326)
|
399
|
+
*
|
400
|
+
* @param args - {@link SwitchChainParameters}
|
401
|
+
*
|
402
|
+
* @example
|
403
|
+
* import { createWalletClient, custom } from 'viem'
|
404
|
+
* import { mainnet, optimism } from 'viem/chains'
|
405
|
+
*
|
406
|
+
* const client = createWalletClient({
|
407
|
+
* chain: mainnet,
|
408
|
+
* transport: custom(window.ethereum),
|
409
|
+
* })
|
410
|
+
* await client.switchChain({ id: optimism.id })
|
411
|
+
*/
|
98
412
|
switchChain: (args: SwitchChainParameters) => Promise<void>
|
413
|
+
/**
|
414
|
+
* Adds an EVM chain to the wallet.
|
415
|
+
*
|
416
|
+
* - Docs: https://viem.sh/docs/actions/wallet/watchAsset.html
|
417
|
+
* - JSON-RPC Methods: [`eth_switchEthereumChain`](https://eips.ethereum.org/EIPS/eip-747)
|
418
|
+
*
|
419
|
+
* @param args - {@link WatchAssetParameters}
|
420
|
+
* @returns Boolean indicating if the token was successfully added. {@link WatchAssetReturnType}
|
421
|
+
*
|
422
|
+
* @example
|
423
|
+
* import { createWalletClient, custom } from 'viem'
|
424
|
+
* import { mainnet } from 'viem/chains'
|
425
|
+
*
|
426
|
+
* const client = createWalletClient({
|
427
|
+
* chain: mainnet,
|
428
|
+
* transport: custom(window.ethereum),
|
429
|
+
* })
|
430
|
+
* const success = await client.watchAsset({
|
431
|
+
* type: 'ERC20',
|
432
|
+
* options: {
|
433
|
+
* address: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
434
|
+
* decimals: 18,
|
435
|
+
* symbol: 'WETH',
|
436
|
+
* },
|
437
|
+
* })
|
438
|
+
*/
|
99
439
|
watchAsset: (args: WatchAssetParameters) => Promise<WatchAssetReturnType>
|
440
|
+
/**
|
441
|
+
* Executes a write function on a contract.
|
442
|
+
*
|
443
|
+
* - Docs: https://viem.sh/docs/contract/writeContract.html
|
444
|
+
* - Examples: https://stackblitz.com/github/wagmi-dev/viem/tree/main/examples/contracts/writing-to-contracts
|
445
|
+
*
|
446
|
+
* A "write" function on a Solidity contract modifies the state of the blockchain. These types of functions require gas to be executed, and hence a [Transaction](https://viem.sh/docs/glossary/terms) is needed to be broadcast in order to change the state.
|
447
|
+
*
|
448
|
+
* Internally, uses a [Wallet Client](https://viem.sh/docs/clients/wallet) to call the [`sendTransaction` action](https://viem.sh/docs/actions/wallet/sendTransaction) with [ABI-encoded `data`](https://viem.sh/docs/contract/encodeFunctionData).
|
449
|
+
*
|
450
|
+
* __Warning: The `write` internally sends a transaction – it does not validate if the contract write will succeed (the contract may throw an error). It is highly recommended to [simulate the contract write with `contract.simulate`](https://viem.sh/docs/contract/writeContract.html#usage) before you execute it.__
|
451
|
+
*
|
452
|
+
* @param args - {@link WriteContractParameters}
|
453
|
+
* @returns A [Transaction Hash](https://viem.sh/docs/glossary/terms#hash). {@link WriteContractReturnType}
|
454
|
+
*
|
455
|
+
* @example
|
456
|
+
* import { createWalletClient, custom, parseAbi } from 'viem'
|
457
|
+
* import { mainnet } from 'viem/chains'
|
458
|
+
*
|
459
|
+
* const client = createWalletClient({
|
460
|
+
* chain: mainnet,
|
461
|
+
* transport: custom(window.ethereum),
|
462
|
+
* })
|
463
|
+
* const hash = await client.writeContract({
|
464
|
+
* address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
|
465
|
+
* abi: parseAbi(['function mint(uint32 tokenId) nonpayable']),
|
466
|
+
* functionName: 'mint',
|
467
|
+
* args: [69420],
|
468
|
+
* })
|
469
|
+
*
|
470
|
+
* @example
|
471
|
+
* // With Validation
|
472
|
+
* import { createWalletClient, custom, parseAbi } from 'viem'
|
473
|
+
* import { mainnet } from 'viem/chains'
|
474
|
+
*
|
475
|
+
* const client = createWalletClient({
|
476
|
+
* chain: mainnet,
|
477
|
+
* transport: custom(window.ethereum),
|
478
|
+
* })
|
479
|
+
* const { request } = await client.simulateContract({
|
480
|
+
* address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
|
481
|
+
* abi: parseAbi(['function mint(uint32 tokenId) nonpayable']),
|
482
|
+
* functionName: 'mint',
|
483
|
+
* args: [69420],
|
484
|
+
* }
|
485
|
+
* const hash = await client.writeContract(request)
|
486
|
+
*/
|
100
487
|
writeContract: <
|
101
488
|
TAbi extends Abi | readonly unknown[],
|
102
489
|
TFunctionName extends string,
|
package/src/errors/version.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export const version = '0.3.
|
1
|
+
export const version = '0.3.2'
|
package/src/utils/rpc.ts
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
import WebSocket from 'isomorphic-ws'
|
2
|
-
import type { MessageEvent } from 'isomorphic-ws'
|
1
|
+
import type { WebSocket, MessageEvent } from 'isomorphic-ws'
|
3
2
|
import {
|
4
3
|
HttpRequestError,
|
5
4
|
RpcRequestError,
|
@@ -145,6 +144,7 @@ export async function getSocket(url_: string) {
|
|
145
144
|
// If the socket already exists, return it.
|
146
145
|
if (socket) return socket
|
147
146
|
|
147
|
+
const { WebSocket } = await import('isomorphic-ws')
|
148
148
|
const webSocket = new WebSocket(url)
|
149
149
|
|
150
150
|
// Set up a cache for incoming "synchronous" requests.
|