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
@@ -16,6 +16,52 @@ export type SignMessageParameters<
|
|
16
16
|
|
17
17
|
export type SignMessageReturnType = Hex
|
18
18
|
|
19
|
+
/**
|
20
|
+
* Calculates an Ethereum-specific signature in [EIP-191 format](https://eips.ethereum.org/EIPS/eip-191): `keccak256("\x19Ethereum Signed Message:\n" + len(message) + message))`.
|
21
|
+
*
|
22
|
+
* - Docs: https://viem.sh/docs/actions/wallet/signMessage.html
|
23
|
+
* - JSON-RPC Methods:
|
24
|
+
* - JSON-RPC Accounts: [`personal_sign`](https://docs.metamask.io/guide/signing-data.html#personal-sign)
|
25
|
+
* - Local Accounts: Signs locally. No JSON-RPC request.
|
26
|
+
*
|
27
|
+
* With the calculated signature, you can:
|
28
|
+
* - use [`verifyMessage`](https://viem.sh/docs/utilities/verifyMessage) to verify the signature,
|
29
|
+
* - use [`recoverMessageAddress`](https://viem.sh/docs/utilities/recoverMessageAddress) to recover the signing address from a signature.
|
30
|
+
*
|
31
|
+
* @param client - Client to use
|
32
|
+
* @param parameters - {@link SignMessageParameters}
|
33
|
+
* @returns The signed message. {@link SignMessageReturnType}
|
34
|
+
*
|
35
|
+
* @example
|
36
|
+
* import { createWalletClient, custom } from 'viem'
|
37
|
+
* import { mainnet } from 'viem/chains'
|
38
|
+
* import { signMessage } from 'viem/wallet'
|
39
|
+
*
|
40
|
+
* const client = createWalletClient({
|
41
|
+
* chain: mainnet,
|
42
|
+
* transport: custom(window.ethereum),
|
43
|
+
* })
|
44
|
+
* const signature = await signMessage(client, {
|
45
|
+
* account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
|
46
|
+
* message: 'hello world',
|
47
|
+
* })
|
48
|
+
*
|
49
|
+
* @example
|
50
|
+
* // Account Hoisting
|
51
|
+
* import { createWalletClient, custom } from 'viem'
|
52
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
53
|
+
* import { mainnet } from 'viem/chains'
|
54
|
+
* import { signMessage } from 'viem/wallet'
|
55
|
+
*
|
56
|
+
* const client = createWalletClient({
|
57
|
+
* account: privateKeyToAccount('0x…'),
|
58
|
+
* chain: mainnet,
|
59
|
+
* transport: custom(window.ethereum),
|
60
|
+
* })
|
61
|
+
* const signature = await signMessage(client, {
|
62
|
+
* message: 'hello world',
|
63
|
+
* })
|
64
|
+
*/
|
19
65
|
export async function signMessage<
|
20
66
|
TChain extends Chain | undefined,
|
21
67
|
TAccount extends Account | undefined,
|
@@ -24,6 +24,104 @@ export type SignTypedDataParameters<
|
|
24
24
|
|
25
25
|
export type SignTypedDataReturnType = Hex
|
26
26
|
|
27
|
+
/**
|
28
|
+
* 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))`.
|
29
|
+
*
|
30
|
+
* - Docs: https://viem.sh/docs/actions/wallet/signTypedData.html
|
31
|
+
* - JSON-RPC Methods:
|
32
|
+
* - JSON-RPC Accounts: [`eth_signTypedData_v4`](https://docs.metamask.io/guide/signing-data.html#signtypeddata-v4)
|
33
|
+
* - Local Accounts: Signs locally. No JSON-RPC request.
|
34
|
+
*
|
35
|
+
* @param client - Client to use
|
36
|
+
* @param parameters - {@link SignTypedDataParameters}
|
37
|
+
* @returns The signed data. {@link SignTypedDataReturnType}
|
38
|
+
*
|
39
|
+
* @example
|
40
|
+
* import { createWalletClient, custom } from 'viem'
|
41
|
+
* import { mainnet } from 'viem/chains'
|
42
|
+
* import { signTypedData } from 'viem/wallet'
|
43
|
+
*
|
44
|
+
* const client = createWalletClient({
|
45
|
+
* chain: mainnet,
|
46
|
+
* transport: custom(window.ethereum),
|
47
|
+
* })
|
48
|
+
* const signature = await signTypedData(client, {
|
49
|
+
* account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
|
50
|
+
* domain: {
|
51
|
+
* name: 'Ether Mail',
|
52
|
+
* version: '1',
|
53
|
+
* chainId: 1,
|
54
|
+
* verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC',
|
55
|
+
* },
|
56
|
+
* types: {
|
57
|
+
* Person: [
|
58
|
+
* { name: 'name', type: 'string' },
|
59
|
+
* { name: 'wallet', type: 'address' },
|
60
|
+
* ],
|
61
|
+
* Mail: [
|
62
|
+
* { name: 'from', type: 'Person' },
|
63
|
+
* { name: 'to', type: 'Person' },
|
64
|
+
* { name: 'contents', type: 'string' },
|
65
|
+
* ],
|
66
|
+
* },
|
67
|
+
* primaryType: 'Mail',
|
68
|
+
* message: {
|
69
|
+
* from: {
|
70
|
+
* name: 'Cow',
|
71
|
+
* wallet: '0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826',
|
72
|
+
* },
|
73
|
+
* to: {
|
74
|
+
* name: 'Bob',
|
75
|
+
* wallet: '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB',
|
76
|
+
* },
|
77
|
+
* contents: 'Hello, Bob!',
|
78
|
+
* },
|
79
|
+
* })
|
80
|
+
*
|
81
|
+
* @example
|
82
|
+
* // Account Hoisting
|
83
|
+
* import { createWalletClient, http } from 'viem'
|
84
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
85
|
+
* import { mainnet } from 'viem/chains'
|
86
|
+
* import { signTypedData } from 'viem/wallet'
|
87
|
+
*
|
88
|
+
* const client = createWalletClient({
|
89
|
+
* account: privateKeyToAccount('0x…'),
|
90
|
+
* chain: mainnet,
|
91
|
+
* transport: http(),
|
92
|
+
* })
|
93
|
+
* const signature = await signTypedData(client, {
|
94
|
+
* domain: {
|
95
|
+
* name: 'Ether Mail',
|
96
|
+
* version: '1',
|
97
|
+
* chainId: 1,
|
98
|
+
* verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC',
|
99
|
+
* },
|
100
|
+
* types: {
|
101
|
+
* Person: [
|
102
|
+
* { name: 'name', type: 'string' },
|
103
|
+
* { name: 'wallet', type: 'address' },
|
104
|
+
* ],
|
105
|
+
* Mail: [
|
106
|
+
* { name: 'from', type: 'Person' },
|
107
|
+
* { name: 'to', type: 'Person' },
|
108
|
+
* { name: 'contents', type: 'string' },
|
109
|
+
* ],
|
110
|
+
* },
|
111
|
+
* primaryType: 'Mail',
|
112
|
+
* message: {
|
113
|
+
* from: {
|
114
|
+
* name: 'Cow',
|
115
|
+
* wallet: '0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826',
|
116
|
+
* },
|
117
|
+
* to: {
|
118
|
+
* name: 'Bob',
|
119
|
+
* wallet: '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB',
|
120
|
+
* },
|
121
|
+
* contents: 'Hello, Bob!',
|
122
|
+
* },
|
123
|
+
* })
|
124
|
+
*/
|
27
125
|
export async function signTypedData<
|
28
126
|
TTypedData extends TypedData | { [key: string]: unknown },
|
29
127
|
TPrimaryType extends string,
|
@@ -2,8 +2,31 @@ import type { Transport, WalletClient } from '../../clients/index.js'
|
|
2
2
|
import type { Account, Chain } from '../../types/index.js'
|
3
3
|
import { numberToHex } from '../../utils/index.js'
|
4
4
|
|
5
|
-
export type SwitchChainParameters = {
|
5
|
+
export type SwitchChainParameters = {
|
6
|
+
/** ID of Chain to switch to */
|
7
|
+
id: Chain['id']
|
8
|
+
}
|
6
9
|
|
10
|
+
/**
|
11
|
+
* Switch the target chain in a wallet.
|
12
|
+
*
|
13
|
+
* - Docs: https://viem.sh/docs/actions/wallet/switchChain.html
|
14
|
+
* - JSON-RPC Methods: [`eth_switchEthereumChain`](https://eips.ethereum.org/EIPS/eip-3326)
|
15
|
+
*
|
16
|
+
* @param client - Client to use
|
17
|
+
* @param parameters - {@link SwitchChainParameters}
|
18
|
+
*
|
19
|
+
* @example
|
20
|
+
* import { createWalletClient, custom } from 'viem'
|
21
|
+
* import { mainnet, optimism } from 'viem/chains'
|
22
|
+
* import { switchChain } from 'viem/wallet'
|
23
|
+
*
|
24
|
+
* const client = createWalletClient({
|
25
|
+
* chain: mainnet,
|
26
|
+
* transport: custom(window.ethereum),
|
27
|
+
* })
|
28
|
+
* await switchChain(client, { id: optimism.id })
|
29
|
+
*/
|
7
30
|
export async function switchChain<
|
8
31
|
TChain extends Chain | undefined,
|
9
32
|
TAccount extends Account | undefined = undefined,
|
@@ -5,6 +5,34 @@ import type { WatchAssetParams } from '../../types/eip1193.js'
|
|
5
5
|
export type WatchAssetParameters = WatchAssetParams
|
6
6
|
export type WatchAssetReturnType = boolean
|
7
7
|
|
8
|
+
/**
|
9
|
+
* Adds an EVM chain to the wallet.
|
10
|
+
*
|
11
|
+
* - Docs: https://viem.sh/docs/actions/wallet/watchAsset.html
|
12
|
+
* - JSON-RPC Methods: [`eth_switchEthereumChain`](https://eips.ethereum.org/EIPS/eip-747)
|
13
|
+
*
|
14
|
+
* @param client - Client to use
|
15
|
+
* @param parameters - {@link WatchAssetParameters}
|
16
|
+
* @returns Boolean indicating if the token was successfully added. {@link WatchAssetReturnType}
|
17
|
+
*
|
18
|
+
* @example
|
19
|
+
* import { createWalletClient, custom } from 'viem'
|
20
|
+
* import { mainnet } from 'viem/chains'
|
21
|
+
* import { watchAsset } from 'viem/wallet'
|
22
|
+
*
|
23
|
+
* const client = createWalletClient({
|
24
|
+
* chain: mainnet,
|
25
|
+
* transport: custom(window.ethereum),
|
26
|
+
* })
|
27
|
+
* const success = await watchAsset(client, {
|
28
|
+
* type: 'ERC20',
|
29
|
+
* options: {
|
30
|
+
* address: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
31
|
+
* decimals: 18,
|
32
|
+
* symbol: 'WETH',
|
33
|
+
* },
|
34
|
+
* })
|
35
|
+
*/
|
8
36
|
export async function watchAsset<
|
9
37
|
TChain extends Chain | undefined,
|
10
38
|
TAccount extends Account | undefined = undefined,
|
@@ -32,6 +32,56 @@ export type WriteContractParameters<
|
|
32
32
|
|
33
33
|
export type WriteContractReturnType = SendTransactionReturnType
|
34
34
|
|
35
|
+
/**
|
36
|
+
* Executes a write function on a contract.
|
37
|
+
*
|
38
|
+
* - Docs: https://viem.sh/docs/contract/writeContract.html
|
39
|
+
* - Examples: https://stackblitz.com/github/wagmi-dev/viem/tree/main/examples/contracts/writing-to-contracts
|
40
|
+
*
|
41
|
+
* 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.
|
42
|
+
*
|
43
|
+
* 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).
|
44
|
+
*
|
45
|
+
* __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.__
|
46
|
+
*
|
47
|
+
* @param client - Client to use
|
48
|
+
* @param parameters - {@link WriteContractParameters}
|
49
|
+
* @returns A [Transaction Hash](https://viem.sh/docs/glossary/terms#hash). {@link WriteContractReturnType}
|
50
|
+
*
|
51
|
+
* @example
|
52
|
+
* import { createWalletClient, custom, parseAbi } from 'viem'
|
53
|
+
* import { mainnet } from 'viem/chains'
|
54
|
+
* import { writeContract } from 'viem/contract'
|
55
|
+
*
|
56
|
+
* const client = createWalletClient({
|
57
|
+
* chain: mainnet,
|
58
|
+
* transport: custom(window.ethereum),
|
59
|
+
* })
|
60
|
+
* const hash = await writeContract(client, {
|
61
|
+
* address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
|
62
|
+
* abi: parseAbi(['function mint(uint32 tokenId) nonpayable']),
|
63
|
+
* functionName: 'mint',
|
64
|
+
* args: [69420],
|
65
|
+
* })
|
66
|
+
*
|
67
|
+
* @example
|
68
|
+
* // With Validation
|
69
|
+
* import { createWalletClient, http, parseAbi } from 'viem'
|
70
|
+
* import { mainnet } from 'viem/chains'
|
71
|
+
* import { simulateContract, writeContract } from 'viem/contract'
|
72
|
+
*
|
73
|
+
* const client = createWalletClient({
|
74
|
+
* chain: mainnet,
|
75
|
+
* transport: http(),
|
76
|
+
* })
|
77
|
+
* const { request } = await simulateContract(client, {
|
78
|
+
* address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
|
79
|
+
* abi: parseAbi(['function mint(uint32 tokenId) nonpayable']),
|
80
|
+
* functionName: 'mint',
|
81
|
+
* args: [69420],
|
82
|
+
* }
|
83
|
+
* const hash = await writeContract(client, request)
|
84
|
+
*/
|
35
85
|
export async function writeContract<
|
36
86
|
TChain extends Chain | undefined,
|
37
87
|
TAccount extends Account | undefined,
|
@@ -24,7 +24,23 @@ export type PublicClient<
|
|
24
24
|
>
|
25
25
|
|
26
26
|
/**
|
27
|
-
*
|
27
|
+
* Creates a Public Client with a given [Transport](https://viem.sh/docs/clients/intro) configured for a [Chain](https://viem.sh/docs/clients/chains).
|
28
|
+
*
|
29
|
+
* - Docs: https://viem.sh/docs/clients/public.html
|
30
|
+
*
|
31
|
+
* A Public Client is an interface to "public" [JSON-RPC API](https://ethereum.org/en/developers/docs/apis/json-rpc/) methods such as retrieving block numbers, transactions, reading from smart contracts, etc through [Public Actions](/docs/actions/public/introduction).
|
32
|
+
*
|
33
|
+
* @param config - {@link PublicClientConfig}
|
34
|
+
* @returns A Public Client. {@link PublicClient}
|
35
|
+
*
|
36
|
+
* @example
|
37
|
+
* import { createPublicClient, http } from 'viem'
|
38
|
+
* import { mainnet } from 'viem/chains'
|
39
|
+
*
|
40
|
+
* const client = createPublicClient({
|
41
|
+
* chain: mainnet,
|
42
|
+
* transport: http(),
|
43
|
+
* })
|
28
44
|
*/
|
29
45
|
export function createPublicClient<
|
30
46
|
TTransport extends Transport,
|
@@ -33,6 +33,26 @@ export type TestClient<
|
|
33
33
|
/**
|
34
34
|
* @description Creates a test client with a given transport.
|
35
35
|
*/
|
36
|
+
/**
|
37
|
+
* Creates a Test Client with a given [Transport](https://viem.sh/docs/clients/intro) configured for a [Chain](https://viem.sh/docs/clients/chains).
|
38
|
+
*
|
39
|
+
* - Docs: https://viem.sh/docs/clients/test.html
|
40
|
+
*
|
41
|
+
* A Test Client is an interface to "test" JSON-RPC API methods accessible through a local Ethereum test node such as [Anvil](https://book.getfoundry.sh/anvil/) or [Hardhat](https://hardhat.org/) such as mining blocks, impersonating accounts, setting fees, etc through [Test Actions](https://viem.sh/docs/actions/test/introduction).
|
42
|
+
*
|
43
|
+
* @param config - {@link TestClientConfig}
|
44
|
+
* @returns A Test Client. {@link TestClient}
|
45
|
+
*
|
46
|
+
* @example
|
47
|
+
* import { createTestClient, custom } from 'viem'
|
48
|
+
* import { foundry } from 'viem/chains'
|
49
|
+
*
|
50
|
+
* const client = createTestClient({
|
51
|
+
* mode: 'anvil',
|
52
|
+
* chain: foundry,
|
53
|
+
* transport: http(),
|
54
|
+
* })
|
55
|
+
*/
|
36
56
|
export function createTestClient<
|
37
57
|
TMode extends TestClientMode,
|
38
58
|
TTransport extends Transport,
|
@@ -44,7 +44,40 @@ export type WalletClient<
|
|
44
44
|
>
|
45
45
|
|
46
46
|
/**
|
47
|
-
*
|
47
|
+
* Creates a Wallet Client with a given [Transport](https://viem.sh/docs/clients/intro) configured for a [Chain](https://viem.sh/docs/clients/chains).
|
48
|
+
*
|
49
|
+
* - Docs: https://viem.sh/docs/clients/wallet.html
|
50
|
+
*
|
51
|
+
* A Wallet Client is an interface to interact with [Ethereum Account(s)](https://ethereum.org/en/glossary/#account) and provides the ability to retrieve accounts, execute transactions, sign messages, etc. through [Wallet Actions](https://viem.sh/docs/actions/wallet/introduction).
|
52
|
+
*
|
53
|
+
* The Wallet Client supports signing over:
|
54
|
+
* - [JSON-RPC Accounts](https://viem.sh/docs/clients/wallet.html#json-rpc-accounts) (e.g. Browser Extension Wallets, WalletConnect, etc).
|
55
|
+
* - [Local Accounts](https://viem.sh/docs/clients/wallet.html#local-accounts-private-key-mnemonic-etc) (e.g. private key/mnemonic wallets).
|
56
|
+
*
|
57
|
+
* @param config - {@link WalletClientConfig}
|
58
|
+
* @returns A Wallet Client. {@link WalletClient}
|
59
|
+
*
|
60
|
+
* @example
|
61
|
+
* // JSON-RPC Account
|
62
|
+
* import { createWalletClient, custom } from 'viem'
|
63
|
+
* import { mainnet } from 'viem/chains'
|
64
|
+
*
|
65
|
+
* const client = createWalletClient({
|
66
|
+
* chain: mainnet,
|
67
|
+
* transport: custom(window.ethereum),
|
68
|
+
* })
|
69
|
+
*
|
70
|
+
* @example
|
71
|
+
* // Local Account
|
72
|
+
* import { createWalletClient, custom } from 'viem'
|
73
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
74
|
+
* import { mainnet } from 'viem/chains'
|
75
|
+
*
|
76
|
+
* const client = createWalletClient({
|
77
|
+
* account: privateKeyToAccount('0x…')
|
78
|
+
* chain: mainnet,
|
79
|
+
* transport: http(),
|
80
|
+
* })
|
48
81
|
*/
|
49
82
|
export function createWalletClient<
|
50
83
|
TTransport extends Transport,
|