From 1f5c28f630923817a507c61b8612f58d6ce771ae Mon Sep 17 00:00:00 2001 From: Dan Forbes Date: Wed, 28 Aug 2024 13:16:10 -0400 Subject: [PATCH] chore(web3js): remove outdated Web3.js guide --- content/tutorials/guide-web3js/10.index.md | 84 ---------------------- content/tutorials/guide-web3js/_dir.yml | 19 ----- 2 files changed, 103 deletions(-) delete mode 100644 content/tutorials/guide-web3js/10.index.md delete mode 100644 content/tutorials/guide-web3js/_dir.yml diff --git a/content/tutorials/guide-web3js/10.index.md b/content/tutorials/guide-web3js/10.index.md deleted file mode 100644 index 3a8be6f9..00000000 --- a/content/tutorials/guide-web3js/10.index.md +++ /dev/null @@ -1,84 +0,0 @@ ---- -title: Using Web3.js to interact with ZKsync -description: Learn how to use Web3js to interact with ZKsync and use built-in functions for ZKsync-specific JSON RPC methods. ---- - -[Web3.js](https://web3js.org/) is a robust and flexible collection of libraries for TypeScript and JavaScript developers. -It serves as an essential tool for connecting and crafting applications within the Ethereum ecosystem -and can be extended to support other networks through its [plugin system](https://docs.web3js.org/guides/web3_plugin_guide/). - -You can use the [ZKsync plugin](https://github.com/web3/web3-plugin-zksync) for Web3.js -to interact with the [ZKsync JSON-RPC API](https://docs.zksync.io/build/api.html) smart contracts deployed on ZKsync. - -## Installation - -Start by adding Web3.js and the ZKsync plugin for Web3.js to your project. -Open your terminal and execute the following command: - -```bash -npm install --save web3 web3-plugin-zksync -``` - -This command installs the latest version of Web3.js and the ZKsync plugin for Web3.js and adds them to your project's dependencies. - -## Initial Setup - -### Initialization - -Before using the ZKsync plugin for Web3.js, you need to [initialize Web3 with a provider](https://docs.web3js.org/#initialize-web3-with-a-provider) -and [register the plugin](https://docs.web3js.org/guides/web3_plugin_guide/plugin_users#registering-the-plugin). - -#### Example - -```javascript -import { Web3 } from "web3"; -import { ZKsyncPlugin } from "web3-plugin-zksync"; - -const zksyncRpcUrl: string = "https://sepolia.era.zksync.dev"; - -console.log(`📞 Connecting to ZKsync Era [${zksyncRpcUrl}]`); -const web3: Web3 = new Web3(zksyncRpcUrl); -web3.registerPlugin(new ZKsyncPlugin(zksyncRpcUrl)); -``` - -::callout{icon="i-heroicons-exclamation-circle"} -This examples uses the %%zk_testnet_name%%. -:: - -### Ethereum JSON-RPC API - -Use the Web3.js `eth` package to fetch data from the ZKsync [Ethereum JSON-RPC API](https://docs.zksync.io/build/api-reference/ethereum-rpc). - -#### Fetch the Latest Block Number - -```javascript - -async function main() { - const blockNumber = await web3.eth.getBlockNumber(); - console.log(`Current block number: ${blockNumber}`); -} - -main().catch(console.error); -``` - -### ZKsync L2-Specific JSON-RPC API - -The ZKsync plugin for Web3.js implements the ZKsync-specific methods -from the `zks_` namespace of the [JSON-RPC API](https://docs.zksync.io/build/api.html#zksync-era-json-rpc-methods). - -#### Fetch the Main Contract Address - - -```javascript -async function main() { - const mainContract = await web3.ZKsync.rpc.getMainContract(); - console.log(`Main contract: ${mainContract}`); -} - -main().catch(console.error); -``` - - -### Wallet Configuration - -Refer to the Web3.js documentation for [details regarding wallet configuration](https://docs.web3js.org/#setting-up-a-wallet). diff --git a/content/tutorials/guide-web3js/_dir.yml b/content/tutorials/guide-web3js/_dir.yml deleted file mode 100644 index a7dadaed..00000000 --- a/content/tutorials/guide-web3js/_dir.yml +++ /dev/null @@ -1,19 +0,0 @@ -title: Using web3.js to interact with ZKsync -featured: false -authors: - - name: ChainSafe - url: https://web3js.org/ - avatar: https://avatars.githubusercontent.com/u/27474093?s=200&v=4 -github_repo: https://github.com/ChainSafe -tags: - - guide - - web3.js -summary: This page will guide you through the steps to use web3.js to interact with ZKsync. -description: This guide outlines how to use the ZKsync web3.js plugin to interact with ZKsync. -what_you_will_learn: - - How to install web3.js and the ZKsync plugin - - How to send RPC requests to ZKsync - - How to use ZKsync-specific methods -updated: 2024-05-09 -tools: - - web3.js