viem 0.0.1-alpha.14 → 0.0.1-alpha.16
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/chains.js +6 -5
- package/dist/chains.js.map +1 -0
- package/dist/chains.mjs +2 -1
- package/dist/chains.mjs.map +1 -0
- package/dist/chunk-4XREGFHD.js +153 -0
- package/dist/chunk-4XREGFHD.js.map +1 -0
- package/dist/{chunk-DUNJAMH5.mjs → chunk-B7A2CAHU.mjs} +95 -480
- package/dist/chunk-B7A2CAHU.mjs.map +1 -0
- package/dist/{chunk-6Z62LPKB.js → chunk-EWTLCB3N.js} +18 -6
- package/dist/chunk-EWTLCB3N.js.map +1 -0
- package/dist/chunk-KCMYVU3Z.mjs +153 -0
- package/dist/chunk-KCMYVU3Z.mjs.map +1 -0
- package/dist/{chunk-KB6CBNKW.mjs → chunk-KM6AFT2K.mjs} +18 -6
- package/dist/chunk-KM6AFT2K.mjs.map +1 -0
- package/dist/chunk-LQXQPPTU.js +256 -0
- package/dist/chunk-LQXQPPTU.js.map +1 -0
- package/dist/{chunk-5TCPFLFT.mjs → chunk-TSJ3OOJW.mjs} +2 -1
- package/dist/chunk-TSJ3OOJW.mjs.map +1 -0
- package/dist/chunk-U7QDLGQL.mjs +256 -0
- package/dist/chunk-U7QDLGQL.mjs.map +1 -0
- package/dist/{chunk-VUNR7KGG.js → chunk-WTXKCAG7.js} +146 -531
- package/dist/chunk-WTXKCAG7.js.map +1 -0
- package/dist/{chunk-E7IQYTLV.js → chunk-XJKOJIX3.js} +12 -11
- package/dist/chunk-XJKOJIX3.js.map +1 -0
- package/dist/clients/index.d.ts +6 -3
- package/dist/clients/index.js +4 -3
- package/dist/clients/index.js.map +1 -0
- package/dist/clients/index.mjs +3 -2
- package/dist/clients/index.mjs.map +1 -0
- package/dist/createClient-cd948138.d.ts +62 -0
- package/dist/createPublicClient-989a0556.d.ts +19 -0
- package/dist/createTestClient-81507f58.d.ts +34 -0
- package/dist/createWalletClient-43f801b9.d.ts +30 -0
- package/dist/{eip1193-c001fcd5.d.ts → eip1193-4330b722.d.ts} +1 -1
- package/dist/index.d.ts +13 -6
- package/dist/index.js +9 -4
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +34 -29
- package/dist/index.mjs.map +1 -0
- package/dist/{parseGwei-21f98a29.d.ts → parseGwei-f2d23de6.d.ts} +1 -1
- package/dist/public.d.ts +12 -0
- package/dist/public.js +59 -0
- package/dist/public.js.map +1 -0
- package/dist/public.mjs +59 -0
- package/dist/public.mjs.map +1 -0
- package/dist/sendTransaction-7a9d241a.d.ts +13 -0
- package/dist/stopImpersonatingAccount-8113150e.d.ts +156 -0
- package/dist/test.d.ts +7 -0
- package/dist/test.js +60 -0
- package/dist/test.js.map +1 -0
- package/dist/test.mjs +60 -0
- package/dist/test.mjs.map +1 -0
- package/dist/{transactionRequest-1d4e4385.d.ts → transactionReceipt-5d332aab.d.ts} +4 -32
- package/dist/transactionRequest-327eb7c2.d.ts +33 -0
- package/dist/utils/index.d.ts +4 -3
- package/dist/utils/index.js +3 -2
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/index.mjs +2 -1
- package/dist/utils/index.mjs.map +1 -0
- package/dist/wallet.d.ts +9 -0
- package/dist/wallet.js +24 -0
- package/dist/wallet.js.map +1 -0
- package/dist/wallet.mjs +24 -0
- package/dist/wallet.mjs.map +1 -0
- package/dist/watchAsset-0088384c.d.ts +39 -0
- package/dist/{stopImpersonatingAccount-fcc5a678.d.ts → watchPendingTransactions-670a7ca3.d.ts} +7 -197
- package/dist/{webSocket-3385e295.d.ts → webSocket-9a3b0b26.d.ts} +1 -1
- package/dist/window.d.ts +1 -1
- package/dist/window.js +1 -1
- package/dist/window.js.map +1 -0
- package/dist/window.mjs +1 -0
- package/dist/window.mjs.map +1 -0
- package/package.json +18 -6
- package/src/_test/abis.ts +1225 -0
- package/src/_test/bench.ts +15 -0
- package/src/_test/constants.ts +63 -0
- package/src/_test/globalSetup.ts +11 -0
- package/src/_test/index.ts +20 -0
- package/src/_test/setup.ts +8 -0
- package/src/_test/utils.ts +112 -0
- package/src/actions/index.test.ts +72 -0
- package/src/actions/index.ts +156 -0
- package/src/actions/public/call.bench.ts +48 -0
- package/src/actions/public/call.test.ts +99 -0
- package/src/actions/public/call.ts +96 -0
- package/src/actions/public/callContract.bench.ts +24 -0
- package/src/actions/public/callContract.test.ts +285 -0
- package/src/actions/public/callContract.ts +80 -0
- package/src/actions/public/createBlockFilter.bench.ts +11 -0
- package/src/actions/public/createBlockFilter.test.ts +9 -0
- package/src/actions/public/createBlockFilter.ts +14 -0
- package/src/actions/public/createEventFilter.test.ts +245 -0
- package/src/actions/public/createEventFilter.ts +81 -0
- package/src/actions/public/createPendingTransactionFilter.bench.ts +11 -0
- package/src/actions/public/createPendingTransactionFilter.test.ts +9 -0
- package/src/actions/public/createPendingTransactionFilter.ts +14 -0
- package/src/actions/public/deployContract.test.ts +56 -0
- package/src/actions/public/deployContract.ts +39 -0
- package/src/actions/public/estimateGas.bench.ts +46 -0
- package/src/actions/public/estimateGas.test.ts +92 -0
- package/src/actions/public/estimateGas.ts +61 -0
- package/src/actions/public/getBalance.test.ts +83 -0
- package/src/actions/public/getBalance.ts +37 -0
- package/src/actions/public/getBlock.bench.ts +28 -0
- package/src/actions/public/getBlock.test.ts +575 -0
- package/src/actions/public/getBlock.ts +66 -0
- package/src/actions/public/getBlockNumber.bench.ts +28 -0
- package/src/actions/public/getBlockNumber.test.ts +27 -0
- package/src/actions/public/getBlockNumber.ts +32 -0
- package/src/actions/public/getBlockTransactionCount.bench.ts +15 -0
- package/src/actions/public/getBlockTransactionCount.test.ts +57 -0
- package/src/actions/public/getBlockTransactionCount.ts +53 -0
- package/src/actions/public/getBytecode.test.ts +27 -0
- package/src/actions/public/getBytecode.ts +32 -0
- package/src/actions/public/getChainId.bench.ts +15 -0
- package/src/actions/public/getChainId.test.ts +8 -0
- package/src/actions/public/getChainId.ts +7 -0
- package/src/actions/public/getFeeHistory.bench.ts +18 -0
- package/src/actions/public/getFeeHistory.test.ts +137 -0
- package/src/actions/public/getFeeHistory.ts +44 -0
- package/src/actions/public/getFilterChanges.bench.ts +13 -0
- package/src/actions/public/getFilterChanges.test.ts +187 -0
- package/src/actions/public/getFilterChanges.ts +23 -0
- package/src/actions/public/getFilterLogs.test.ts +102 -0
- package/src/actions/public/getFilterLogs.ts +20 -0
- package/src/actions/public/getGasPrice.bench.ts +28 -0
- package/src/actions/public/getGasPrice.test.ts +8 -0
- package/src/actions/public/getGasPrice.ts +15 -0
- package/src/actions/public/getTransaction.bench.ts +33 -0
- package/src/actions/public/getTransaction.test.ts +311 -0
- package/src/actions/public/getTransaction.ts +96 -0
- package/src/actions/public/getTransactionConfirmations.test.ts +69 -0
- package/src/actions/public/getTransactionConfirmations.ts +39 -0
- package/src/actions/public/getTransactionCount.test.ts +56 -0
- package/src/actions/public/getTransactionCount.ts +34 -0
- package/src/actions/public/getTransactionReceipt.bench.ts +33 -0
- package/src/actions/public/getTransactionReceipt.test.ts +217 -0
- package/src/actions/public/getTransactionReceipt.ts +35 -0
- package/src/actions/public/index.test.ts +36 -0
- package/src/actions/public/index.ts +120 -0
- package/src/actions/public/uninstallFilter.bench.ts +13 -0
- package/src/actions/public/uninstallFilter.test.ts +65 -0
- package/src/actions/public/uninstallFilter.ts +17 -0
- package/src/actions/public/waitForTransactionReceipt.test.ts +322 -0
- package/src/actions/public/waitForTransactionReceipt.ts +171 -0
- package/src/actions/public/watchBlockNumber.test.ts +166 -0
- package/src/actions/public/watchBlockNumber.ts +79 -0
- package/src/actions/public/watchBlocks.test.ts +185 -0
- package/src/actions/public/watchBlocks.ts +95 -0
- package/src/actions/public/watchPendingTransactions.test.ts +116 -0
- package/src/actions/public/watchPendingTransactions.ts +73 -0
- package/src/actions/test/dropTransaction.test.ts +34 -0
- package/src/actions/test/dropTransaction.ts +17 -0
- package/src/actions/test/getAutomine.test.ts +14 -0
- package/src/actions/test/getAutomine.ts +11 -0
- package/src/actions/test/getTxpoolContent.test.ts +45 -0
- package/src/actions/test/getTxpoolContent.ts +7 -0
- package/src/actions/test/getTxpoolStatus.test.ts +41 -0
- package/src/actions/test/getTxpoolStatus.ts +12 -0
- package/src/actions/test/impersonateAccount.test.ts +28 -0
- package/src/actions/test/impersonateAccount.ts +17 -0
- package/src/actions/test/increaseTime.test.ts +18 -0
- package/src/actions/test/increaseTime.ts +17 -0
- package/src/actions/test/index.test.ts +38 -0
- package/src/actions/test/index.ts +77 -0
- package/src/actions/test/inspectTxpool.test.ts +50 -0
- package/src/actions/test/inspectTxpool.ts +7 -0
- package/src/actions/test/mine.test.ts +20 -0
- package/src/actions/test/mine.ts +16 -0
- package/src/actions/test/removeBlockTimestampInterval.test.ts +23 -0
- package/src/actions/test/removeBlockTimestampInterval.ts +7 -0
- package/src/actions/test/reset.test.ts +19 -0
- package/src/actions/test/reset.ts +18 -0
- package/src/actions/test/revert.test.ts +39 -0
- package/src/actions/test/revert.ts +14 -0
- package/src/actions/test/sendUnsignedTransaction.test.ts +52 -0
- package/src/actions/test/sendUnsignedTransaction.ts +19 -0
- package/src/actions/test/setAutomine.test.ts +14 -0
- package/src/actions/test/setAutomine.ts +8 -0
- package/src/actions/test/setBalance.test.ts +29 -0
- package/src/actions/test/setBalance.ts +20 -0
- package/src/actions/test/setBlockGasLimit.test.ts +21 -0
- package/src/actions/test/setBlockGasLimit.ts +17 -0
- package/src/actions/test/setBlockTimestampInterval.test.ts +23 -0
- package/src/actions/test/setBlockTimestampInterval.ts +16 -0
- package/src/actions/test/setCode.test.ts +26 -0
- package/src/actions/test/setCode.ts +19 -0
- package/src/actions/test/setCoinbase.test.ts +11 -0
- package/src/actions/test/setCoinbase.ts +17 -0
- package/src/actions/test/setIntervalMining.test.ts +30 -0
- package/src/actions/test/setIntervalMining.ts +16 -0
- package/src/actions/test/setLoggingEnabled.test.ts +10 -0
- package/src/actions/test/setLoggingEnabled.ts +8 -0
- package/src/actions/test/setMinGasPrice.test.ts +22 -0
- package/src/actions/test/setMinGasPrice.ts +17 -0
- package/src/actions/test/setNextBlockBaseFeePerGas.test.ts +23 -0
- package/src/actions/test/setNextBlockBaseFeePerGas.ts +17 -0
- package/src/actions/test/setNextBlockTimestamp.test.ts +19 -0
- package/src/actions/test/setNextBlockTimestamp.ts +17 -0
- package/src/actions/test/setNonce.test.ts +28 -0
- package/src/actions/test/setNonce.ts +20 -0
- package/src/actions/test/setRpcUrl.test.ts +9 -0
- package/src/actions/test/setRpcUrl.ts +8 -0
- package/src/actions/test/setStorageAt.test.ts +36 -0
- package/src/actions/test/setStorageAt.ts +26 -0
- package/src/actions/test/snapshot.test.ts +18 -0
- package/src/actions/test/snapshot.ts +7 -0
- package/src/actions/test/stopImpersonatingAccount.test.ts +31 -0
- package/src/actions/test/stopImpersonatingAccount.ts +17 -0
- package/src/actions/wallet/addChain.test.ts +14 -0
- package/src/actions/wallet/addChain.ts +21 -0
- package/src/actions/wallet/getAccounts.test.ts +22 -0
- package/src/actions/wallet/getAccounts.ts +7 -0
- package/src/actions/wallet/getPermissions.test.ts +24 -0
- package/src/actions/wallet/getPermissions.ts +9 -0
- package/src/actions/wallet/index.test.ts +19 -0
- package/src/actions/wallet/index.ts +27 -0
- package/src/actions/wallet/requestAccounts.test.ts +13 -0
- package/src/actions/wallet/requestAccounts.ts +7 -0
- package/src/actions/wallet/requestPermissions.test.ts +26 -0
- package/src/actions/wallet/requestPermissions.ts +19 -0
- package/src/actions/wallet/sendTransaction.bench.ts +57 -0
- package/src/actions/wallet/sendTransaction.test.ts +440 -0
- package/src/actions/wallet/sendTransaction.ts +76 -0
- package/src/actions/wallet/signMessage.test.ts +62 -0
- package/src/actions/wallet/signMessage.ts +35 -0
- package/src/actions/wallet/switchChain.test.ts +22 -0
- package/src/actions/wallet/switchChain.ts +19 -0
- package/src/actions/wallet/watchAsset.test.ts +41 -0
- package/src/actions/wallet/watchAsset.ts +16 -0
- package/src/chains.test.ts +1134 -0
- package/src/chains.ts +167 -0
- package/src/clients/createClient.test.ts +295 -0
- package/src/clients/createClient.ts +81 -0
- package/src/clients/createPublicClient.test.ts +165 -0
- package/src/clients/createPublicClient.ts +49 -0
- package/src/clients/createTestClient.test.ts +145 -0
- package/src/clients/createTestClient.ts +72 -0
- package/src/clients/createWalletClient.test.ts +121 -0
- package/src/clients/createWalletClient.ts +54 -0
- package/src/clients/index.test.ts +19 -0
- package/src/clients/index.ts +31 -0
- package/src/clients/transports/createTransport.test.ts +58 -0
- package/src/clients/transports/createTransport.ts +48 -0
- package/src/clients/transports/custom.test.ts +98 -0
- package/src/clients/transports/custom.ts +34 -0
- package/src/clients/transports/fallback.test.ts +223 -0
- package/src/clients/transports/fallback.ts +48 -0
- package/src/clients/transports/http.test.ts +110 -0
- package/src/clients/transports/http.ts +51 -0
- package/src/clients/transports/index.test.ts +15 -0
- package/src/clients/transports/index.ts +17 -0
- package/src/clients/transports/webSocket.test.ts +164 -0
- package/src/clients/transports/webSocket.ts +117 -0
- package/src/constants.test.ts +27 -0
- package/src/constants.ts +18 -0
- package/src/errors/abi.test.ts +83 -0
- package/src/errors/abi.ts +238 -0
- package/src/errors/address.test.ts +14 -0
- package/src/errors/address.ts +9 -0
- package/src/errors/base.test.ts +72 -0
- package/src/errors/base.ts +57 -0
- package/src/errors/block.test.ts +24 -0
- package/src/errors/block.ts +18 -0
- package/src/errors/contract.ts +125 -0
- package/src/errors/data.ts +20 -0
- package/src/errors/encoding.ts +60 -0
- package/src/errors/index.ts +77 -0
- package/src/errors/log.ts +8 -0
- package/src/errors/request.test.ts +331 -0
- package/src/errors/request.ts +163 -0
- package/src/errors/rpc.test.ts +88 -0
- package/src/errors/rpc.ts +113 -0
- package/src/errors/transaction.test.ts +83 -0
- package/src/errors/transaction.ts +54 -0
- package/src/errors/transport.test.ts +12 -0
- package/src/errors/transport.ts +12 -0
- package/src/index.test.ts +208 -0
- package/src/index.ts +353 -0
- package/src/public.ts +80 -0
- package/src/test.ts +51 -0
- package/src/types/block.ts +71 -0
- package/src/types/contract.ts +327 -0
- package/src/types/eip1193.ts +1038 -0
- package/src/types/fee.ts +47 -0
- package/src/types/filter.ts +8 -0
- package/src/types/index.ts +72 -0
- package/src/types/log.ts +22 -0
- package/src/types/misc.ts +4 -0
- package/src/types/rpc.ts +35 -0
- package/src/types/transaction.ts +145 -0
- package/src/types/utils.ts +67 -0
- package/src/types/window.ts +9 -0
- package/src/utils/abi/decodeAbi.bench.ts +135 -0
- package/src/utils/abi/decodeAbi.test.ts +1615 -0
- package/src/utils/abi/decodeAbi.ts +296 -0
- package/src/utils/abi/decodeDeployData.test.ts +159 -0
- package/src/utils/abi/decodeDeployData.ts +41 -0
- package/src/utils/abi/decodeErrorResult.test.ts +130 -0
- package/src/utils/abi/decodeErrorResult.ts +28 -0
- package/src/utils/abi/decodeFunctionData.test.ts +140 -0
- package/src/utils/abi/decodeFunctionData.ts +29 -0
- package/src/utils/abi/decodeFunctionResult.test.ts +262 -0
- package/src/utils/abi/decodeFunctionResult.ts +53 -0
- package/src/utils/abi/encodeAbi.bench.ts +163 -0
- package/src/utils/abi/encodeAbi.test.ts +1414 -0
- package/src/utils/abi/encodeAbi.ts +258 -0
- package/src/utils/abi/encodeDeployData.test.ts +131 -0
- package/src/utils/abi/encodeDeployData.ts +37 -0
- package/src/utils/abi/encodeErrorResult.test.ts +197 -0
- package/src/utils/abi/encodeErrorResult.ts +40 -0
- package/src/utils/abi/encodeEventTopics.test.ts +348 -0
- package/src/utils/abi/encodeEventTopics.ts +69 -0
- package/src/utils/abi/encodeFunctionData.test.ts +140 -0
- package/src/utils/abi/encodeFunctionData.ts +38 -0
- package/src/utils/abi/encodeFunctionResult.test.ts +284 -0
- package/src/utils/abi/encodeFunctionResult.ts +39 -0
- package/src/utils/abi/formatAbiItemWithArgs.test.ts +291 -0
- package/src/utils/abi/formatAbiItemWithArgs.ts +27 -0
- package/src/utils/abi/formatAbiItemWithParams.test.ts +335 -0
- package/src/utils/abi/formatAbiItemWithParams.ts +41 -0
- package/src/utils/abi/getAbiItem.ts +5 -0
- package/src/utils/abi/index.test.ts +23 -0
- package/src/utils/abi/index.ts +38 -0
- package/src/utils/address/getAddress.bench.ts +22 -0
- package/src/utils/address/getAddress.test.ts +46 -0
- package/src/utils/address/getAddress.ts +28 -0
- package/src/utils/address/getContractAddress.bench.ts +20 -0
- package/src/utils/address/getContractAddress.test.ts +78 -0
- package/src/utils/address/getContractAddress.ts +59 -0
- package/src/utils/address/index.test.ts +17 -0
- package/src/utils/address/index.ts +16 -0
- package/src/utils/address/isAddress.test.ts +10 -0
- package/src/utils/address/isAddress.ts +10 -0
- package/src/utils/address/isAddressEqual.test.ts +55 -0
- package/src/utils/address/isAddressEqual.ts +6 -0
- package/src/utils/buildRequest.test.ts +365 -0
- package/src/utils/buildRequest.ts +45 -0
- package/src/utils/contract/extractFunctionParts.test.ts +109 -0
- package/src/utils/contract/extractFunctionParts.ts +27 -0
- package/src/utils/contract/getContractError.test.ts +97 -0
- package/src/utils/contract/getContractError.ts +70 -0
- package/src/utils/contract/index.test.ts +15 -0
- package/src/utils/contract/index.ts +8 -0
- package/src/utils/data/concat.test.ts +35 -0
- package/src/utils/data/concat.ts +34 -0
- package/src/utils/data/index.test.ts +23 -0
- package/src/utils/data/index.ts +13 -0
- package/src/utils/data/isBytes.test.ts +9 -0
- package/src/utils/data/isBytes.ts +7 -0
- package/src/utils/data/isHex.test.ts +13 -0
- package/src/utils/data/isHex.ts +5 -0
- package/src/utils/data/pad.bench.ts +39 -0
- package/src/utils/data/pad.test.ts +367 -0
- package/src/utils/data/pad.ts +53 -0
- package/src/utils/data/size.test.ts +18 -0
- package/src/utils/data/size.ts +13 -0
- package/src/utils/data/slice.test.ts +203 -0
- package/src/utils/data/slice.ts +60 -0
- package/src/utils/data/trim.bench.ts +50 -0
- package/src/utils/data/trim.test.ts +175 -0
- package/src/utils/data/trim.ts +33 -0
- package/src/utils/encoding/decodeBytes.bench.ts +40 -0
- package/src/utils/encoding/decodeBytes.test.ts +144 -0
- package/src/utils/encoding/decodeBytes.ts +63 -0
- package/src/utils/encoding/decodeHex.bench.ts +24 -0
- package/src/utils/encoding/decodeHex.test.ts +167 -0
- package/src/utils/encoding/decodeHex.ts +76 -0
- package/src/utils/encoding/decodeRlp.bench.ts +34 -0
- package/src/utils/encoding/decodeRlp.test.ts +350 -0
- package/src/utils/encoding/decodeRlp.ts +121 -0
- package/src/utils/encoding/encodeBytes.bench.ts +41 -0
- package/src/utils/encoding/encodeBytes.test.ts +676 -0
- package/src/utils/encoding/encodeBytes.ts +59 -0
- package/src/utils/encoding/encodeHex.bench.ts +60 -0
- package/src/utils/encoding/encodeHex.test.ts +232 -0
- package/src/utils/encoding/encodeHex.ts +104 -0
- package/src/utils/encoding/encodeRlp.bench.ts +54 -0
- package/src/utils/encoding/encodeRlp.test.ts +254 -0
- package/src/utils/encoding/encodeRlp.ts +48 -0
- package/src/utils/encoding/index.test.ts +32 -0
- package/src/utils/encoding/index.ts +36 -0
- package/src/utils/formatters/block.bench.ts +51 -0
- package/src/utils/formatters/block.test.ts +115 -0
- package/src/utils/formatters/block.ts +36 -0
- package/src/utils/formatters/extract.test.ts +14 -0
- package/src/utils/formatters/extract.ts +18 -0
- package/src/utils/formatters/feeHistory.test.ts +66 -0
- package/src/utils/formatters/feeHistory.ts +12 -0
- package/src/utils/formatters/format.test.ts +93 -0
- package/src/utils/formatters/format.ts +53 -0
- package/src/utils/formatters/index.test.ts +17 -0
- package/src/utils/formatters/index.ts +24 -0
- package/src/utils/formatters/log.test.ts +79 -0
- package/src/utils/formatters/log.ts +12 -0
- package/src/utils/formatters/transaction.test.ts +271 -0
- package/src/utils/formatters/transaction.ts +51 -0
- package/src/utils/formatters/transactionReceipt.bench.ts +73 -0
- package/src/utils/formatters/transactionReceipt.test.ts +151 -0
- package/src/utils/formatters/transactionReceipt.ts +54 -0
- package/src/utils/formatters/transactionRequest.bench.ts +29 -0
- package/src/utils/formatters/transactionRequest.test.ts +237 -0
- package/src/utils/formatters/transactionRequest.ts +47 -0
- package/src/utils/hash/getEventSignature.test.ts +61 -0
- package/src/utils/hash/getEventSignature.ts +4 -0
- package/src/utils/hash/getFunctionSignature.test.ts +22 -0
- package/src/utils/hash/getFunctionSignature.ts +5 -0
- package/src/utils/hash/hashFunction.test.ts +65 -0
- package/src/utils/hash/hashFunction.ts +12 -0
- package/src/utils/hash/index.test.ts +13 -0
- package/src/utils/hash/index.ts +5 -0
- package/src/utils/hash/keccak256.test.ts +59 -0
- package/src/utils/hash/keccak256.ts +23 -0
- package/src/utils/index.test.ts +87 -0
- package/src/utils/index.ts +126 -0
- package/src/utils/observe.test.ts +176 -0
- package/src/utils/observe.ts +66 -0
- package/src/utils/poll.test.ts +127 -0
- package/src/utils/poll.ts +42 -0
- package/src/utils/promise/index.test.ts +14 -0
- package/src/utils/promise/index.ts +3 -0
- package/src/utils/promise/withCache.test.ts +97 -0
- package/src/utils/promise/withCache.ts +73 -0
- package/src/utils/promise/withRetry.test.ts +231 -0
- package/src/utils/promise/withRetry.ts +61 -0
- package/src/utils/promise/withTimeout.test.ts +37 -0
- package/src/utils/promise/withTimeout.ts +39 -0
- package/src/utils/rpc.test.ts +992 -0
- package/src/utils/rpc.ts +292 -0
- package/src/utils/stringify.test.ts +13 -0
- package/src/utils/stringify.ts +5 -0
- package/src/utils/uid.ts +14 -0
- package/src/utils/unit/formatEther.test.ts +75 -0
- package/src/utils/unit/formatEther.ts +6 -0
- package/src/utils/unit/formatGwei.test.ts +32 -0
- package/src/utils/unit/formatGwei.ts +6 -0
- package/src/utils/unit/formatUnit.bench.ts +26 -0
- package/src/utils/unit/formatUnit.test.ts +40 -0
- package/src/utils/unit/formatUnit.ts +16 -0
- package/src/utils/unit/index.test.ts +16 -0
- package/src/utils/unit/index.ts +6 -0
- package/src/utils/unit/parseEther.test.ts +126 -0
- package/src/utils/unit/parseEther.ts +6 -0
- package/src/utils/unit/parseGwei.test.ts +50 -0
- package/src/utils/unit/parseGwei.ts +6 -0
- package/src/utils/unit/parseUnit.bench.ts +26 -0
- package/src/utils/unit/parseUnit.test.ts +54 -0
- package/src/utils/unit/parseUnit.ts +27 -0
- package/src/utils/wait.ts +3 -0
- package/src/wallet.ts +23 -0
- package/src/window.ts +1 -0
- package/actions/package.json +0 -4
- package/dist/actions/index.d.ts +0 -8
- package/dist/actions/index.js +0 -129
- package/dist/actions/index.mjs +0 -129
- package/dist/createWalletClient-3f9fa8b6.d.ts +0 -130
@@ -0,0 +1,15 @@
|
|
1
|
+
import { providers } from 'ethers'
|
2
|
+
import Web3 from 'web3'
|
3
|
+
import { JsonRpcProvider } from 'essential-eth'
|
4
|
+
|
5
|
+
import { localhost } from '../chains'
|
6
|
+
|
7
|
+
export const ethersProvider = new providers.JsonRpcProvider(
|
8
|
+
localhost.rpcUrls.default.http[0],
|
9
|
+
)
|
10
|
+
|
11
|
+
export const web3Provider = new Web3(localhost.rpcUrls.default.http[0])
|
12
|
+
|
13
|
+
export const essentialProvider = new JsonRpcProvider(
|
14
|
+
localhost.rpcUrls.default.http[0],
|
15
|
+
)
|
@@ -0,0 +1,63 @@
|
|
1
|
+
import type { Hex } from '../types'
|
2
|
+
|
3
|
+
export const accounts = [
|
4
|
+
{
|
5
|
+
address: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
|
6
|
+
balance: 10000000000000000000000n,
|
7
|
+
},
|
8
|
+
{
|
9
|
+
address: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
|
10
|
+
balance: 10000000000000000000000n,
|
11
|
+
},
|
12
|
+
{
|
13
|
+
address: '0x3c44cdddb6a900fa2b585dd299e03d12fa4293bc',
|
14
|
+
balance: 10000000000000000000000n,
|
15
|
+
},
|
16
|
+
{
|
17
|
+
address: '0x90f79bf6eb2c4f870365e785982e1f101e93b906',
|
18
|
+
balance: 10000000000000000000000n,
|
19
|
+
},
|
20
|
+
{
|
21
|
+
address: '0x15d34aaf54267db7d7c367839aaf71a00a2c6a65',
|
22
|
+
balance: 10000000000000000000000n,
|
23
|
+
},
|
24
|
+
{
|
25
|
+
address: '0x9965507d1a55bcc2695c58ba16fb37d819b0a4dc',
|
26
|
+
balance: 10000000000000000000000n,
|
27
|
+
},
|
28
|
+
{
|
29
|
+
address: '0x976ea74026e726554db657fa54763abd0c3a0aa9',
|
30
|
+
balance: 10000000000000000000000n,
|
31
|
+
},
|
32
|
+
{
|
33
|
+
address: '0x14dc79964da2c08b23698b3d3cc7ca32193d9955',
|
34
|
+
balance: 10000000000000000000000n,
|
35
|
+
},
|
36
|
+
{
|
37
|
+
address: '0x23618e81e3f5cdf7f54c3d65f7fbc0abf5b21e8f',
|
38
|
+
balance: 10000000000000000000000n,
|
39
|
+
},
|
40
|
+
{
|
41
|
+
address: '0xa0ee7a142d267c1f36714e4a8f75612f20a79720',
|
42
|
+
balance: 10000000000000000000000n,
|
43
|
+
},
|
44
|
+
] as const
|
45
|
+
|
46
|
+
export const initialBlockNumber = BigInt(
|
47
|
+
Number(process.env.VITE_ANVIL_BLOCK_NUMBER),
|
48
|
+
)
|
49
|
+
|
50
|
+
export const localHttpUrl = 'http://127.0.0.1:8545'
|
51
|
+
export const localWsUrl = 'ws://127.0.0.1:8545'
|
52
|
+
|
53
|
+
// ERC20 `transferFrom` method
|
54
|
+
export const transfer1Data = (address: string): Hex =>
|
55
|
+
`0xa9059cbb000000000000000000000000${address
|
56
|
+
.slice(2)
|
57
|
+
.toLowerCase()}0000000000000000000000000000000000000000000000000000000000000001`
|
58
|
+
|
59
|
+
// vitalik.eth
|
60
|
+
export const vitalikAddress = '0xd8da6bf26964af9d7eed9e03e53415d37aa96045'
|
61
|
+
|
62
|
+
// USDC ERC20 contract
|
63
|
+
export const usdcAddress = '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import { testClient } from './utils'
|
2
|
+
import { reset, setAutomine, setIntervalMining } from '../actions'
|
3
|
+
|
4
|
+
export async function setup() {
|
5
|
+
await reset(testClient, {
|
6
|
+
blockNumber: BigInt(parseInt(process.env.VITE_ANVIL_BLOCK_NUMBER!)),
|
7
|
+
jsonRpcUrl: process.env.VITE_ANVIL_FORK_URL,
|
8
|
+
})
|
9
|
+
await setAutomine(testClient, false)
|
10
|
+
await setIntervalMining(testClient, { interval: 1 })
|
11
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
export { wagmiContractConfig } from './abis'
|
2
|
+
|
3
|
+
export { essentialProvider, ethersProvider, web3Provider } from './bench'
|
4
|
+
|
5
|
+
export {
|
6
|
+
accounts,
|
7
|
+
initialBlockNumber,
|
8
|
+
localHttpUrl,
|
9
|
+
localWsUrl,
|
10
|
+
transfer1Data,
|
11
|
+
usdcAddress,
|
12
|
+
vitalikAddress,
|
13
|
+
} from './constants'
|
14
|
+
|
15
|
+
export {
|
16
|
+
createHttpServer,
|
17
|
+
publicClient,
|
18
|
+
testClient,
|
19
|
+
walletClient,
|
20
|
+
} from './utils'
|
@@ -0,0 +1,112 @@
|
|
1
|
+
/* c8 ignore start */
|
2
|
+
import { localhost } from '../chains'
|
3
|
+
import {
|
4
|
+
createPublicClient,
|
5
|
+
createTestClient,
|
6
|
+
createWalletClient,
|
7
|
+
custom,
|
8
|
+
http,
|
9
|
+
webSocket,
|
10
|
+
} from '../clients'
|
11
|
+
import { rpc } from '../utils'
|
12
|
+
import { RpcError } from '../types/eip1193'
|
13
|
+
import { accounts, localWsUrl } from './constants'
|
14
|
+
|
15
|
+
import type { RequestListener } from 'http'
|
16
|
+
import { createServer } from 'http'
|
17
|
+
import type { AddressInfo } from 'net'
|
18
|
+
|
19
|
+
export const publicClient =
|
20
|
+
process.env.VITE_NETWORK_TRANSPORT_MODE === 'webSocket'
|
21
|
+
? createPublicClient({
|
22
|
+
chain: localhost,
|
23
|
+
pollingInterval: 1_000,
|
24
|
+
transport: webSocket(localWsUrl),
|
25
|
+
})
|
26
|
+
: createPublicClient({
|
27
|
+
chain: localhost,
|
28
|
+
pollingInterval: 1_000,
|
29
|
+
transport: http(),
|
30
|
+
})
|
31
|
+
|
32
|
+
export const walletClient = createWalletClient({
|
33
|
+
transport: custom({
|
34
|
+
on: (message: string, listener: (...args: any[]) => null) => {
|
35
|
+
if (message === 'accountsChanged') {
|
36
|
+
listener([accounts[0].address] as any)
|
37
|
+
}
|
38
|
+
},
|
39
|
+
removeListener: () => null,
|
40
|
+
request: async ({ method, params }: any) => {
|
41
|
+
if (method === 'eth_requestAccounts') {
|
42
|
+
return [accounts[0].address]
|
43
|
+
}
|
44
|
+
if (method === 'personal_sign') {
|
45
|
+
method = 'eth_sign'
|
46
|
+
params = [params[1], params[0]]
|
47
|
+
}
|
48
|
+
if (method === 'wallet_watchAsset') {
|
49
|
+
if (params[0].type === 'ERC721') {
|
50
|
+
throw new RpcError(-32602, 'Token type ERC721 not supported.')
|
51
|
+
}
|
52
|
+
return true
|
53
|
+
}
|
54
|
+
if (method === 'wallet_addEthereumChain') return null
|
55
|
+
if (method === 'wallet_switchEthereumChain') {
|
56
|
+
if (params[0].chainId === '0xfa') {
|
57
|
+
throw new RpcError(-4902, 'Unrecognized chain.')
|
58
|
+
}
|
59
|
+
return null
|
60
|
+
}
|
61
|
+
if (
|
62
|
+
method === 'wallet_getPermissions' ||
|
63
|
+
method === 'wallet_requestPermissions'
|
64
|
+
)
|
65
|
+
return [
|
66
|
+
{
|
67
|
+
invoker: 'https://example.com',
|
68
|
+
parentCapability: 'eth_accounts',
|
69
|
+
caveats: [
|
70
|
+
{
|
71
|
+
type: 'filterResponse',
|
72
|
+
value: ['0x0c54fccd2e384b4bb6f2e405bf5cbc15a017aafb'],
|
73
|
+
},
|
74
|
+
],
|
75
|
+
},
|
76
|
+
]
|
77
|
+
|
78
|
+
const { result } = await rpc.http(localhost.rpcUrls.default.http[0], {
|
79
|
+
body: {
|
80
|
+
method,
|
81
|
+
params,
|
82
|
+
},
|
83
|
+
})
|
84
|
+
return result
|
85
|
+
},
|
86
|
+
}),
|
87
|
+
})
|
88
|
+
|
89
|
+
export const testClient = createTestClient({
|
90
|
+
chain: localhost,
|
91
|
+
mode: 'anvil',
|
92
|
+
transport: http(),
|
93
|
+
})
|
94
|
+
|
95
|
+
export function createHttpServer(
|
96
|
+
handler: RequestListener,
|
97
|
+
): Promise<{ close: () => Promise<unknown>; url: string }> {
|
98
|
+
const server = createServer(handler)
|
99
|
+
|
100
|
+
const closeAsync = () =>
|
101
|
+
new Promise((resolve, reject) =>
|
102
|
+
server.close((err) => (err ? reject(err) : resolve(undefined))),
|
103
|
+
)
|
104
|
+
|
105
|
+
return new Promise((resolve) => {
|
106
|
+
server.listen(() => {
|
107
|
+
const { port } = server.address() as AddressInfo
|
108
|
+
resolve({ close: closeAsync, url: `http://localhost:${port}` })
|
109
|
+
})
|
110
|
+
})
|
111
|
+
}
|
112
|
+
/* c8 ignore stop */
|
@@ -0,0 +1,72 @@
|
|
1
|
+
import { expect, test } from 'vitest'
|
2
|
+
|
3
|
+
import * as actions from './index'
|
4
|
+
|
5
|
+
test('exports actions', () => {
|
6
|
+
expect(actions).toMatchInlineSnapshot(`
|
7
|
+
{
|
8
|
+
"addChain": [Function],
|
9
|
+
"call": [Function],
|
10
|
+
"callContract": [Function],
|
11
|
+
"createBlockFilter": [Function],
|
12
|
+
"createPendingTransactionFilter": [Function],
|
13
|
+
"deployContract": [Function],
|
14
|
+
"dropTransaction": [Function],
|
15
|
+
"estimateGas": [Function],
|
16
|
+
"getAccounts": [Function],
|
17
|
+
"getAutomine": [Function],
|
18
|
+
"getBalance": [Function],
|
19
|
+
"getBlock": [Function],
|
20
|
+
"getBlockNumber": [Function],
|
21
|
+
"getBlockNumberCache": [Function],
|
22
|
+
"getBlockTransactionCount": [Function],
|
23
|
+
"getBytecode": [Function],
|
24
|
+
"getChainId": [Function],
|
25
|
+
"getFeeHistory": [Function],
|
26
|
+
"getFilterChanges": [Function],
|
27
|
+
"getFilterLogs": [Function],
|
28
|
+
"getGasPrice": [Function],
|
29
|
+
"getPermissions": [Function],
|
30
|
+
"getTransaction": [Function],
|
31
|
+
"getTransactionConfirmations": [Function],
|
32
|
+
"getTransactionCount": [Function],
|
33
|
+
"getTransactionReceipt": [Function],
|
34
|
+
"getTxpoolContent": [Function],
|
35
|
+
"getTxpoolStatus": [Function],
|
36
|
+
"impersonateAccount": [Function],
|
37
|
+
"increaseTime": [Function],
|
38
|
+
"inspectTxpool": [Function],
|
39
|
+
"mine": [Function],
|
40
|
+
"removeBlockTimestampInterval": [Function],
|
41
|
+
"requestAccounts": [Function],
|
42
|
+
"requestPermissions": [Function],
|
43
|
+
"reset": [Function],
|
44
|
+
"revert": [Function],
|
45
|
+
"sendTransaction": [Function],
|
46
|
+
"sendUnsignedTransaction": [Function],
|
47
|
+
"setAutomine": [Function],
|
48
|
+
"setBalance": [Function],
|
49
|
+
"setBlockGasLimit": [Function],
|
50
|
+
"setBlockTimestampInterval": [Function],
|
51
|
+
"setCode": [Function],
|
52
|
+
"setCoinbase": [Function],
|
53
|
+
"setIntervalMining": [Function],
|
54
|
+
"setLoggingEnabled": [Function],
|
55
|
+
"setMinGasPrice": [Function],
|
56
|
+
"setNextBlockBaseFeePerGas": [Function],
|
57
|
+
"setNextBlockTimestamp": [Function],
|
58
|
+
"setNonce": [Function],
|
59
|
+
"setStorageAt": [Function],
|
60
|
+
"signMessage": [Function],
|
61
|
+
"snapshot": [Function],
|
62
|
+
"stopImpersonatingAccount": [Function],
|
63
|
+
"switchChain": [Function],
|
64
|
+
"uninstallFilter": [Function],
|
65
|
+
"waitForTransactionReceipt": [Function],
|
66
|
+
"watchAsset": [Function],
|
67
|
+
"watchBlockNumber": [Function],
|
68
|
+
"watchBlocks": [Function],
|
69
|
+
"watchPendingTransactions": [Function],
|
70
|
+
}
|
71
|
+
`)
|
72
|
+
})
|
@@ -0,0 +1,156 @@
|
|
1
|
+
export {
|
2
|
+
call,
|
3
|
+
callContract,
|
4
|
+
createBlockFilter,
|
5
|
+
createPendingTransactionFilter,
|
6
|
+
deployContract,
|
7
|
+
estimateGas,
|
8
|
+
getBalance,
|
9
|
+
getBlock,
|
10
|
+
getBlockNumber,
|
11
|
+
getBlockNumberCache,
|
12
|
+
getBlockTransactionCount,
|
13
|
+
getBytecode,
|
14
|
+
getChainId,
|
15
|
+
getFeeHistory,
|
16
|
+
getFilterChanges,
|
17
|
+
getFilterLogs,
|
18
|
+
getGasPrice,
|
19
|
+
getTransaction,
|
20
|
+
getTransactionConfirmations,
|
21
|
+
getTransactionCount,
|
22
|
+
getTransactionReceipt,
|
23
|
+
uninstallFilter,
|
24
|
+
waitForTransactionReceipt,
|
25
|
+
watchBlockNumber,
|
26
|
+
watchBlocks,
|
27
|
+
watchPendingTransactions,
|
28
|
+
} from './public'
|
29
|
+
export type {
|
30
|
+
CallArgs,
|
31
|
+
CallContractArgs,
|
32
|
+
CallContractResponse,
|
33
|
+
CallResponse,
|
34
|
+
CreateBlockFilterResponse,
|
35
|
+
CreatePendingTransactionFilterResponse,
|
36
|
+
DeployContractArgs,
|
37
|
+
DeployContractResponse,
|
38
|
+
EstimateGasArgs,
|
39
|
+
EstimateGasResponse,
|
40
|
+
GetBalanceArgs,
|
41
|
+
GetBalanceResponse,
|
42
|
+
GetBlockArgs,
|
43
|
+
GetBlockNumberArgs,
|
44
|
+
GetBlockNumberResponse,
|
45
|
+
GetBlockResponse,
|
46
|
+
GetBlockTransactionCountArgs,
|
47
|
+
GetBlockTransactionCountResponse,
|
48
|
+
GetBytecodeArgs,
|
49
|
+
GetBytecodeResponse,
|
50
|
+
GetFeeHistoryArgs,
|
51
|
+
GetFeeHistoryResponse,
|
52
|
+
GetFilterChangesArgs,
|
53
|
+
GetFilterChangesResponse,
|
54
|
+
GetFilterLogsArgs,
|
55
|
+
GetFilterLogsResponse,
|
56
|
+
GetGasPriceResponse,
|
57
|
+
GetTransactionArgs,
|
58
|
+
GetTransactionConfirmationsArgs,
|
59
|
+
GetTransactionConfirmationsResponse,
|
60
|
+
GetTransactionCountArgs,
|
61
|
+
GetTransactionCountResponse,
|
62
|
+
GetTransactionReceiptArgs,
|
63
|
+
GetTransactionReceiptResponse,
|
64
|
+
GetTransactionResponse,
|
65
|
+
OnBlock,
|
66
|
+
OnBlockNumber,
|
67
|
+
OnBlockNumberResponse,
|
68
|
+
OnBlockResponse,
|
69
|
+
OnTransactions,
|
70
|
+
OnTransactionsResponse,
|
71
|
+
ReplacementReason,
|
72
|
+
ReplacementResponse,
|
73
|
+
UninstallFilterArgs,
|
74
|
+
UninstallFilterResponse,
|
75
|
+
WaitForTransactionReceiptArgs,
|
76
|
+
WaitForTransactionReceiptResponse,
|
77
|
+
WatchBlockNumberArgs,
|
78
|
+
WatchBlocksArgs,
|
79
|
+
WatchPendingTransactionsArgs,
|
80
|
+
} from './public'
|
81
|
+
|
82
|
+
export {
|
83
|
+
dropTransaction,
|
84
|
+
getAutomine,
|
85
|
+
getTxpoolContent,
|
86
|
+
getTxpoolStatus,
|
87
|
+
impersonateAccount,
|
88
|
+
increaseTime,
|
89
|
+
inspectTxpool,
|
90
|
+
mine,
|
91
|
+
removeBlockTimestampInterval,
|
92
|
+
reset,
|
93
|
+
revert,
|
94
|
+
sendUnsignedTransaction,
|
95
|
+
setAutomine,
|
96
|
+
setBalance,
|
97
|
+
setBlockGasLimit,
|
98
|
+
setBlockTimestampInterval,
|
99
|
+
setCode,
|
100
|
+
setCoinbase,
|
101
|
+
setIntervalMining,
|
102
|
+
setLoggingEnabled,
|
103
|
+
setMinGasPrice,
|
104
|
+
setNextBlockBaseFeePerGas,
|
105
|
+
setNextBlockTimestamp,
|
106
|
+
setNonce,
|
107
|
+
setStorageAt,
|
108
|
+
snapshot,
|
109
|
+
stopImpersonatingAccount,
|
110
|
+
} from './test'
|
111
|
+
export type {
|
112
|
+
DropTransactionArgs,
|
113
|
+
ImpersonateAccountArgs,
|
114
|
+
IncreaseTimeArgs,
|
115
|
+
MineArgs,
|
116
|
+
ResetArgs,
|
117
|
+
RevertArgs,
|
118
|
+
SendUnsignedTransactionArgs,
|
119
|
+
SendUnsignedTransactionResponse,
|
120
|
+
SetBalanceArgs,
|
121
|
+
SetBlockGasLimitArgs,
|
122
|
+
SetBlockTimestampIntervalArgs,
|
123
|
+
SetCodeArgs,
|
124
|
+
SetCoinbaseArgs,
|
125
|
+
SetIntervalMiningArgs,
|
126
|
+
SetMinGasPriceArgs,
|
127
|
+
SetNextBlockBaseFeePerGasArgs,
|
128
|
+
SetNextBlockTimestampArgs,
|
129
|
+
SetNonceArgs,
|
130
|
+
SetStorageAtArgs,
|
131
|
+
StopImpersonatingAccountArgs,
|
132
|
+
} from './test'
|
133
|
+
|
134
|
+
export {
|
135
|
+
addChain,
|
136
|
+
getAccounts,
|
137
|
+
getPermissions,
|
138
|
+
requestAccounts,
|
139
|
+
requestPermissions,
|
140
|
+
sendTransaction,
|
141
|
+
signMessage,
|
142
|
+
switchChain,
|
143
|
+
watchAsset,
|
144
|
+
} from './wallet'
|
145
|
+
export type {
|
146
|
+
FormattedTransactionRequest,
|
147
|
+
GetPermissionsResponse,
|
148
|
+
RequestPermissionsResponse,
|
149
|
+
SendTransactionArgs,
|
150
|
+
SendTransactionResponse,
|
151
|
+
SignMessageArgs,
|
152
|
+
SignMessageResponse,
|
153
|
+
SwitchChainArgs,
|
154
|
+
WatchAssetArgs,
|
155
|
+
WatchAssetResponse,
|
156
|
+
} from './wallet'
|
@@ -0,0 +1,48 @@
|
|
1
|
+
import { bench, describe } from 'vitest'
|
2
|
+
|
3
|
+
import {
|
4
|
+
accounts,
|
5
|
+
essentialProvider,
|
6
|
+
ethersProvider,
|
7
|
+
publicClient,
|
8
|
+
web3Provider,
|
9
|
+
} from '../../_test'
|
10
|
+
|
11
|
+
import { call } from './call'
|
12
|
+
|
13
|
+
const wagmiContractAddress = '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2'
|
14
|
+
const name4bytes = '0x06fdde03'
|
15
|
+
|
16
|
+
describe('Call', () => {
|
17
|
+
bench('viem: `call`', async () => {
|
18
|
+
await call(publicClient, {
|
19
|
+
data: name4bytes,
|
20
|
+
from: accounts[0].address,
|
21
|
+
to: wagmiContractAddress,
|
22
|
+
})
|
23
|
+
})
|
24
|
+
|
25
|
+
bench('ethers: `call`', async () => {
|
26
|
+
await ethersProvider.call({
|
27
|
+
data: name4bytes,
|
28
|
+
from: accounts[0].address,
|
29
|
+
to: wagmiContractAddress,
|
30
|
+
})
|
31
|
+
})
|
32
|
+
|
33
|
+
bench('web3.js: `call`', async () => {
|
34
|
+
await web3Provider.eth.call({
|
35
|
+
data: name4bytes,
|
36
|
+
from: accounts[0].address,
|
37
|
+
to: wagmiContractAddress,
|
38
|
+
})
|
39
|
+
})
|
40
|
+
|
41
|
+
bench('essential-eth: `call`', async () => {
|
42
|
+
await essentialProvider.call({
|
43
|
+
data: name4bytes,
|
44
|
+
from: accounts[0].address,
|
45
|
+
to: wagmiContractAddress,
|
46
|
+
})
|
47
|
+
})
|
48
|
+
})
|
@@ -0,0 +1,99 @@
|
|
1
|
+
import { expect, test } from 'vitest'
|
2
|
+
|
3
|
+
import { accounts, publicClient } from '../../_test'
|
4
|
+
import { celo } from '../../chains'
|
5
|
+
import { createPublicClient, http } from '../../clients'
|
6
|
+
import { numberToHex, parseGwei } from '../../utils'
|
7
|
+
|
8
|
+
import { call } from './call'
|
9
|
+
|
10
|
+
const wagmiContractAddress = '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2'
|
11
|
+
const name4bytes = '0x06fdde03'
|
12
|
+
const mint4bytes = '0x1249c58b'
|
13
|
+
const mintWithParams4bytes = '0xa0712d68'
|
14
|
+
const fourTwenty =
|
15
|
+
'00000000000000000000000000000000000000000000000000000000000001a4'
|
16
|
+
|
17
|
+
const sourceAccount = accounts[0]
|
18
|
+
|
19
|
+
test('default', async () => {
|
20
|
+
const { data } = await call(publicClient, {
|
21
|
+
data: name4bytes,
|
22
|
+
from: sourceAccount.address,
|
23
|
+
to: wagmiContractAddress,
|
24
|
+
})
|
25
|
+
expect(data).toMatchInlineSnapshot(
|
26
|
+
'"0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000057761676d69000000000000000000000000000000000000000000000000000000"',
|
27
|
+
)
|
28
|
+
})
|
29
|
+
|
30
|
+
test('custom formatter', async () => {
|
31
|
+
const client = createPublicClient({
|
32
|
+
chain: celo,
|
33
|
+
transport: http(),
|
34
|
+
})
|
35
|
+
|
36
|
+
const { data } = await call(client, {
|
37
|
+
chain: celo,
|
38
|
+
gatewayFee: numberToHex(1n),
|
39
|
+
data: name4bytes,
|
40
|
+
from: sourceAccount.address,
|
41
|
+
to: wagmiContractAddress,
|
42
|
+
})
|
43
|
+
expect(data).toBeUndefined()
|
44
|
+
})
|
45
|
+
|
46
|
+
test('zero data', async () => {
|
47
|
+
const { data } = await call(publicClient, {
|
48
|
+
data: mint4bytes,
|
49
|
+
from: sourceAccount.address,
|
50
|
+
to: wagmiContractAddress,
|
51
|
+
})
|
52
|
+
expect(data).toMatchInlineSnapshot('undefined')
|
53
|
+
})
|
54
|
+
|
55
|
+
test('args: blockNumber', async () => {
|
56
|
+
const { data } = await call(publicClient, {
|
57
|
+
blockNumber: 15564164n,
|
58
|
+
data: `${mintWithParams4bytes}${fourTwenty}`,
|
59
|
+
from: sourceAccount.address,
|
60
|
+
to: wagmiContractAddress,
|
61
|
+
})
|
62
|
+
expect(data).toMatchInlineSnapshot('undefined')
|
63
|
+
})
|
64
|
+
|
65
|
+
test('errors: maxFeePerGas less than maxPriorityFeePerGas', async () => {
|
66
|
+
await expect(
|
67
|
+
call(publicClient, {
|
68
|
+
data: `${mintWithParams4bytes}${fourTwenty}`,
|
69
|
+
from: sourceAccount.address,
|
70
|
+
to: wagmiContractAddress,
|
71
|
+
maxFeePerGas: parseGwei('20'),
|
72
|
+
maxPriorityFeePerGas: parseGwei('22'),
|
73
|
+
}),
|
74
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(`
|
75
|
+
"\`maxFeePerGas\` cannot be less than \`maxPriorityFeePerGas\`
|
76
|
+
|
77
|
+
Version: viem@1.0.2"
|
78
|
+
`)
|
79
|
+
})
|
80
|
+
|
81
|
+
test('errors: contract revert (contract error)', async () => {
|
82
|
+
await expect(
|
83
|
+
call(publicClient, {
|
84
|
+
data: `${mintWithParams4bytes}${fourTwenty}`,
|
85
|
+
from: sourceAccount.address,
|
86
|
+
to: wagmiContractAddress,
|
87
|
+
}),
|
88
|
+
).rejects.toThrowError('execution reverted: Token ID is taken')
|
89
|
+
})
|
90
|
+
|
91
|
+
test('errors: contract revert (insufficient params)', async () => {
|
92
|
+
await expect(
|
93
|
+
call(publicClient, {
|
94
|
+
data: mintWithParams4bytes,
|
95
|
+
from: sourceAccount.address,
|
96
|
+
to: wagmiContractAddress,
|
97
|
+
}),
|
98
|
+
).rejects.toThrowError('execution reverted')
|
99
|
+
})
|
@@ -0,0 +1,96 @@
|
|
1
|
+
import type { Chain, Formatter } from '../../chains'
|
2
|
+
import type { PublicClient } from '../../clients'
|
3
|
+
import { InvalidGasArgumentsError } from '../../errors'
|
4
|
+
import type {
|
5
|
+
Address,
|
6
|
+
BlockTag,
|
7
|
+
Hex,
|
8
|
+
MergeIntersectionProperties,
|
9
|
+
TransactionRequest,
|
10
|
+
} from '../../types'
|
11
|
+
import { extract, Formatted, TransactionRequestFormatter } from '../../utils'
|
12
|
+
import { format, formatTransactionRequest, numberToHex } from '../../utils'
|
13
|
+
|
14
|
+
export type FormattedCall<
|
15
|
+
TFormatter extends Formatter | undefined = Formatter,
|
16
|
+
> = MergeIntersectionProperties<
|
17
|
+
Formatted<TFormatter, TransactionRequest, true>,
|
18
|
+
TransactionRequest
|
19
|
+
>
|
20
|
+
|
21
|
+
export type CallArgs<TChain extends Chain = Chain> = FormattedCall<
|
22
|
+
TransactionRequestFormatter<TChain>
|
23
|
+
> & {
|
24
|
+
chain?: TChain
|
25
|
+
from?: Address
|
26
|
+
} & (
|
27
|
+
| {
|
28
|
+
/** The balance of the account at a block number. */
|
29
|
+
blockNumber?: bigint
|
30
|
+
blockTag?: never
|
31
|
+
}
|
32
|
+
| {
|
33
|
+
blockNumber?: never
|
34
|
+
/** The balance of the account at a block tag. */
|
35
|
+
blockTag?: BlockTag
|
36
|
+
}
|
37
|
+
)
|
38
|
+
|
39
|
+
export type CallResponse = { data: Hex | undefined }
|
40
|
+
|
41
|
+
export async function call<TChain extends Chain>(
|
42
|
+
client: PublicClient,
|
43
|
+
{
|
44
|
+
blockNumber,
|
45
|
+
blockTag = 'latest',
|
46
|
+
chain,
|
47
|
+
from,
|
48
|
+
accessList,
|
49
|
+
data,
|
50
|
+
gas,
|
51
|
+
gasPrice,
|
52
|
+
maxFeePerGas,
|
53
|
+
maxPriorityFeePerGas,
|
54
|
+
nonce,
|
55
|
+
to,
|
56
|
+
value,
|
57
|
+
...rest
|
58
|
+
}: CallArgs<TChain>,
|
59
|
+
): Promise<CallResponse> {
|
60
|
+
if (
|
61
|
+
maxFeePerGas !== undefined &&
|
62
|
+
maxPriorityFeePerGas !== undefined &&
|
63
|
+
maxFeePerGas < maxPriorityFeePerGas
|
64
|
+
)
|
65
|
+
throw new InvalidGasArgumentsError()
|
66
|
+
|
67
|
+
const blockNumberHex = blockNumber ? numberToHex(blockNumber) : undefined
|
68
|
+
|
69
|
+
const formatter = chain?.formatters?.transactionRequest
|
70
|
+
const request_ = format(
|
71
|
+
{
|
72
|
+
from,
|
73
|
+
accessList,
|
74
|
+
data,
|
75
|
+
gas,
|
76
|
+
gasPrice,
|
77
|
+
maxFeePerGas,
|
78
|
+
maxPriorityFeePerGas,
|
79
|
+
nonce,
|
80
|
+
to,
|
81
|
+
value,
|
82
|
+
// Pick out extra data that might exist on the chain's transaction request type.
|
83
|
+
...extract(rest, { formatter }),
|
84
|
+
} as TransactionRequest,
|
85
|
+
{
|
86
|
+
formatter: formatter || formatTransactionRequest,
|
87
|
+
},
|
88
|
+
)
|
89
|
+
|
90
|
+
const response = await client.request({
|
91
|
+
method: 'eth_call',
|
92
|
+
params: [request_, blockNumberHex || blockTag],
|
93
|
+
})
|
94
|
+
if (response === '0x') return { data: undefined }
|
95
|
+
return { data: response }
|
96
|
+
}
|