From 7dc8cc1af74607fc1c9f34a3ffa7fa632cce7b03 Mon Sep 17 00:00:00 2001 From: Mark Stacey Date: Thu, 28 Mar 2024 14:51:11 -0230 Subject: [PATCH] chore: Add deprecation notice (#469) * chore: Add deprecation notice Add a deprecation notice, and an example of how to build a basic provider using the newer packages we have replaced this with. * Note the versions of packages used in the example * Update code block to use JavaScript syntax highlighting rather than TypeScript * Fix code highlighting * Another attempt at fixing code highlighting * Revert back to TypeScript highlighting, which worked for some reason * Attempt to fix highlighting by adding space after > * Update example to work cross-platform * Update message about replacement to clarify that it's not an exhaustive list --- README.md | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a5c1f446..dee1c45e 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,43 @@ Web3 ProviderEngine is a tool for composing your own [web3 providers](https://github.com/ethereum/wiki/wiki/JavaScript-API#web3). -

⚠️ PLEASE READ ⚠️

This package was originally created for MetaMask and is being phased out in favor of @metamask/json-rpc-engine and @metamask/eth-json-rpc-middleware. As such, we will no longer be accepting changes to this package except those which address security issues.
+> [!CAUTION] +> This package has been deprecated. +> +> This package was originally created for MetaMask, but has been replaced by `@metamask/json-rpc-engine`, `@metamask/eth-json-rpc-middleware`, `@metamask/eth-json-rpc-provider`, and various other packages. +> +> Here is an example of how to create a provider using those packages: +> +> ```javascript +> import { providerFromMiddleware } from '@metamask/eth-json-rpc-provider'; +> import { createFetchMiddleware } from '@metamask/eth-json-rpc-middleware'; +> import { valueToBytes, bytesToBase64 } from '@metamask/utils'; +> import fetch from 'cross-fetch'; +> +> const rpcUrl = '[insert RPC URL here]'; +> +> const fetchMiddleware = createFetchMiddleware({ +> btoa: (stringToEncode) => bytesToBase64(valueToBytes(stringToEncode)), +> fetch, +> rpcUrl, +> }); +> const provider = providerFromMiddleware(fetchMiddleware); +> +> provider.sendAsync( +> { id: 1, jsonrpc: '2.0', method: 'eth_chainId' }, +> (error, response) => { +> if (error) { +> console.error(error); +> } else { +> console.log(response.result); +> } +> } +> ); +> ``` +> +> This example was written with v12.1.0 of `@metamask/eth-json-rpc-middleware`, v3.0.1 of `@metamask/eth-json-rpc-provider`, and v8.4.0 of `@metamask/utils`. +> + ### Composable