From 770e489894804ddb23016de8f556a8707a446569 Mon Sep 17 00:00:00 2001 From: murphyyue Date: Thu, 14 Mar 2024 11:12:04 +0800 Subject: [PATCH 1/7] =?UTF-8?q?fix(01=5FHelloVitalik):=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8Den=E4=B8=AD=E7=9A=84ethers=E5=BC=95=E5=85=A5=E6=96=B9?= =?UTF-8?q?=E5=BC=8F=E4=BB=A5=E5=8F=8A=E5=A2=9E=E5=8A=A0=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 01_HelloVitalik/HelloVitalik.js | 12 +++++++----- en/01_HelloVitalik/HelloVitalik.js | 3 ++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/01_HelloVitalik/HelloVitalik.js b/01_HelloVitalik/HelloVitalik.js index 00cd6d2..7b0ec48 100644 --- a/01_HelloVitalik/HelloVitalik.js +++ b/01_HelloVitalik/HelloVitalik.js @@ -5,12 +5,14 @@ import { ethers } from "ethers"; // 利用ethers默认的Provider连接以太坊网络 // const provider = new ethers.getDefaultProvider(); -const ALCHEMY_MAINNET_URL = 'https://eth-mainnet.g.alchemy.com/v2/oKmOQKbneVkxgHZfibs-iFhIlIAl6HDN'; +// 注意:如果当前的URL无法使用,需要主动去NFURA或者ALCHEMY官网注册并获得URl +const ALCHEMY_MAINNET_URL = "https://eth-mainnet.g.alchemy.com/v2/oKmOQKbneVkxgHZfibs-iFhIlIAl6HDN"; const provider = new ethers.JsonRpcProvider(ALCHEMY_MAINNET_URL) const main = async () => { - // 查询vitalik的ETH余额 - const balance = await provider.getBalance(`vitalik.eth`); - // 将余额输出在console - console.log(`ETH Balance of vitalik: ${ethers.formatEther(balance)} ETH`);} + // 查询vitalik的ETH余额 + const balance = await provider.getBalance(`vitalik.eth`); //0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045 + // 将余额输出在console + console.log(`ETH Balance of vitalik: ${ethers.formatEther(balance)} ETH`); +} main() \ No newline at end of file diff --git a/en/01_HelloVitalik/HelloVitalik.js b/en/01_HelloVitalik/HelloVitalik.js index dfb69c9..8a251f4 100644 --- a/en/01_HelloVitalik/HelloVitalik.js +++ b/en/01_HelloVitalik/HelloVitalik.js @@ -1,10 +1,11 @@ // Import the ethers package -const { ethers } = require("ethers"); +import { ethers } from "ethers"; // playcode's free version cannot install ethers, use this command to import the package from the internet (comment out the line above) // import { ethers } from "https://cdnjs.cloudflare.com/ajax/libs/ethers/6.2.3/ethers.js"; // Connect to the Ethereum network using any desired provider (e.g INFURA or ALCHEMY) // const provider = new ethers.JsonRpcProvider(); +// Note: if the current URL cannot be used, you need to register at NFURA or ALCHEMY's official website and get URL by yourself. const provider = new ethers.JsonRpcProvider(`https://mainnet.infura.io/v3/8b9750710d56460d940aeff47967c4ba`) // Specify the address you want to query const address = '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045' //or 'vitalik.eth' From 8766cf36987ef2ca0bb570c0400af3dc3eabbf7b Mon Sep 17 00:00:00 2001 From: murphyyue Date: Thu, 14 Mar 2024 11:17:09 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- en/01_HelloVitalik/HelloVitalik.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/en/01_HelloVitalik/HelloVitalik.js b/en/01_HelloVitalik/HelloVitalik.js index 8a251f4..f0c0ba1 100644 --- a/en/01_HelloVitalik/HelloVitalik.js +++ b/en/01_HelloVitalik/HelloVitalik.js @@ -5,7 +5,7 @@ import { ethers } from "ethers"; // Connect to the Ethereum network using any desired provider (e.g INFURA or ALCHEMY) // const provider = new ethers.JsonRpcProvider(); -// Note: if the current URL cannot be used, you need to register at NFURA or ALCHEMY's official website and get URL by yourself. +// Note: if the current URL cannot be used, you need to register at INFURA or ALCHEMY's official website and get URL by yourself. const provider = new ethers.JsonRpcProvider(`https://mainnet.infura.io/v3/8b9750710d56460d940aeff47967c4ba`) // Specify the address you want to query const address = '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045' //or 'vitalik.eth' From e71e763fe8f76f27fe43e415687d92c27f53450b Mon Sep 17 00:00:00 2001 From: murphyyue Date: Thu, 14 Mar 2024 11:19:37 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E5=AE=8C=E5=96=84=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 01_HelloVitalik/HelloVitalik.js | 6 +++--- en/01_HelloVitalik/HelloVitalik.js | 20 +++++++++++--------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/01_HelloVitalik/HelloVitalik.js b/01_HelloVitalik/HelloVitalik.js index 7b0ec48..7a4e25f 100644 --- a/01_HelloVitalik/HelloVitalik.js +++ b/01_HelloVitalik/HelloVitalik.js @@ -7,12 +7,12 @@ import { ethers } from "ethers"; // const provider = new ethers.getDefaultProvider(); // 注意:如果当前的URL无法使用,需要主动去NFURA或者ALCHEMY官网注册并获得URl const ALCHEMY_MAINNET_URL = "https://eth-mainnet.g.alchemy.com/v2/oKmOQKbneVkxgHZfibs-iFhIlIAl6HDN"; -const provider = new ethers.JsonRpcProvider(ALCHEMY_MAINNET_URL) +const provider = new ethers.JsonRpcProvider(ALCHEMY_MAINNET_URL); const main = async () => { // 查询vitalik的ETH余额 const balance = await provider.getBalance(`vitalik.eth`); //0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045 // 将余额输出在console console.log(`ETH Balance of vitalik: ${ethers.formatEther(balance)} ETH`); -} -main() \ No newline at end of file +}; +main(); diff --git a/en/01_HelloVitalik/HelloVitalik.js b/en/01_HelloVitalik/HelloVitalik.js index f0c0ba1..0b3bc7c 100644 --- a/en/01_HelloVitalik/HelloVitalik.js +++ b/en/01_HelloVitalik/HelloVitalik.js @@ -3,17 +3,19 @@ import { ethers } from "ethers"; // playcode's free version cannot install ethers, use this command to import the package from the internet (comment out the line above) // import { ethers } from "https://cdnjs.cloudflare.com/ajax/libs/ethers/6.2.3/ethers.js"; -// Connect to the Ethereum network using any desired provider (e.g INFURA or ALCHEMY) +// Connect to the Ethereum network using any desired provider (e.g INFURA or ALCHEMY) // const provider = new ethers.JsonRpcProvider(); // Note: if the current URL cannot be used, you need to register at INFURA or ALCHEMY's official website and get URL by yourself. -const provider = new ethers.JsonRpcProvider(`https://mainnet.infura.io/v3/8b9750710d56460d940aeff47967c4ba`) +const provider = new ethers.JsonRpcProvider( + `https://mainnet.infura.io/v3/8b9750710d56460d940aeff47967c4ba`, +); // Specify the address you want to query -const address = '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045' //or 'vitalik.eth' +const address = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"; //or 'vitalik.eth' const main = async () => { - // Query the ETH balance of vitalik - const balance = await provider.getBalance(address) //or 'vitalik.eth' - // Output the balance to the console - console.log(`\nETH Balance of ${address} --> ${ethers.formatEther(balance)} ETH\n`) - } -main() + // Query the ETH balance of vitalik + const balance = await provider.getBalance(address); //or 'vitalik.eth' + // Output the balance to the console + console.log(`\nETH Balance of ${address} --> ${ethers.formatEther(balance)} ETH\n`); +}; +main(); From 4e750bfb4097a47de16c6f154b6e099872650082 Mon Sep 17 00:00:00 2001 From: murphyyue Date: Thu, 14 Mar 2024 11:41:05 +0800 Subject: [PATCH 4/7] =?UTF-8?q?=E5=AE=8C=E5=96=84=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- en/01_HelloVitalik/readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/en/01_HelloVitalik/readme.md b/en/01_HelloVitalik/readme.md index 3aa7969..cccf221 100644 --- a/en/01_HelloVitalik/readme.md +++ b/en/01_HelloVitalik/readme.md @@ -81,7 +81,7 @@ Let's analyze the program line by line: The first line fetches the installed `ethers` library: ```javascript -const { ethers } require "ethers"; +import { ethers } from "ethers"; ``` If you are using the `playcode` platform where free accounts cannot install external libraries, you can directly import from the `ethers` CDN (for educational purposes only due to security considerations): ```javascript From 841da1874f5e9942cd9384934ed448cbd5ff938d Mon Sep 17 00:00:00 2001 From: murphyyue Date: Sat, 16 Mar 2024 15:33:21 +0800 Subject: [PATCH 5/7] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 03_ReadContract/ReadContract.js | 2 +- 04_SendETH/SendETH.js | 4 ++-- en/02_Provider/Provider.js | 20 ++++++++++---------- en/02_Provider/readme.md | 2 +- en/03_ReadContract/ReadContract.js | 2 +- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/03_ReadContract/ReadContract.js b/03_ReadContract/ReadContract.js index 1871d3c..2c3bb95 100644 --- a/03_ReadContract/ReadContract.js +++ b/03_ReadContract/ReadContract.js @@ -6,7 +6,7 @@ import { ethers } from "ethers"; // 利用Alchemy的rpc节点连接以太坊网络 // 准备 alchemy API 可以参考https://github.com/AmazingAng/WTFSolidity/blob/main/Topics/Tools/TOOL04_Alchemy/readme.md -const ALCHEMY_MAINNET_URL = 'https://eth-mainnet.g.alchemy.com/v2/oKmOQKbneVkxgHZfibs-iFhIlIAl6HDN'; +const ALCHEMY_MAINNET_URL = "https://eth-mainnet.g.alchemy.com/v2/xvx-3ZrK3AdmeL2dzMVqzJcCiejbiSbs"; const provider = new ethers.JsonRpcProvider(ALCHEMY_MAINNET_URL); // 第1种输入abi的方式: 复制abi全文 diff --git a/04_SendETH/SendETH.js b/04_SendETH/SendETH.js index cca0eb3..294d2dd 100644 --- a/04_SendETH/SendETH.js +++ b/04_SendETH/SendETH.js @@ -4,7 +4,7 @@ import { ethers } from "ethers"; // 利用Alchemy的rpc节点连接以太坊测试网络 // 准备 alchemy API 可以参考https://github.com/AmazingAng/WTFSolidity/blob/main/Topics/Tools/TOOL04_Alchemy/readme.md -const ALCHEMY_GOERLI_URL = 'https://eth-goerli.alchemyapi.io/v2/GlaeWuylnNM3uuOo-SAwJxuwTdqHaY5l'; +const ALCHEMY_GOERLI_URL = "https://eth-mainnet.g.alchemy.com/v2/xvx-3ZrK3AdmeL2dzMVqzJcCiejbiSbs"; const provider = new ethers.JsonRpcProvider(ALCHEMY_GOERLI_URL); // 创建随机的wallet对象 @@ -13,7 +13,7 @@ const wallet1WithProvider = wallet1.connect(provider) const mnemonic = wallet1.mnemonic // 获取助记词 // 利用私钥和provider创建wallet对象 -const privateKey = '0x227dbb8586117d55284e26620bc76534dfbd2394be34cf4a09cb775d593b6f2b' +const privateKey = "b3e0cc0591ef7d6018e69984045cf8d54933ad207c21a55caec240fa2ed5791b"; const wallet2 = new ethers.Wallet(privateKey, provider) // 从助记词创建wallet对象 diff --git a/en/02_Provider/Provider.js b/en/02_Provider/Provider.js index 8f03434..8433695 100644 --- a/en/02_Provider/Provider.js +++ b/en/02_Provider/Provider.js @@ -1,16 +1,16 @@ // Import the ethers package -const { ethers } require "ethers"; +import { ethers } from "ethers"; // For the free version of playcode that cannot install ethers, use this command to import the package from the web (comment out the line above) // import { ethers } from "https://cdn-cors.ethers.io/lib/ethers-5.6.9.esm.min.js"; // Connect to the Ethereum network using Infura's RPC node // Prepare the Infura API by signing up on app.infura.io -const INFURA_MAINNET_URL = new ethers.JsonRpcProvider(`https://mainnet.infura.io/v3/8b9750710d56460d940aeff47967c4ba`) +const INFURA_MAINNET_URL = new ethers.JsonRpcProvider(`https://eth-mainnet.g.alchemy.com/v2/xvx-3ZrK3AdmeL2dzMVqzJcCiejbiSbs`) const SEPOLIA_TESTNET_URL = new ethers.JsonRpcProvider('https://sepolia.infura.io/v3/8b9750710d56460d940aeff47967c4ba') // Connect to the Ethereum mainnet const providerETH = new ethers.JsonRpcProvider(INFURA_MAINNET_URL) // Connect to the Sepolia testing network -const providerSepolia = new ethers.JsonRpcProvider(INFURA_SEPOLIA_URL) +const providerSepolia = new ethers.JsonRpcProvider(SEPOLIA_TESTNET_URL) const main = async () => { // Retrieve on-chain information using the provider @@ -24,35 +24,35 @@ const main = async () => { console.log(`\nSepoliaETH Balance of ${address} --> ${ethers.formatEther(balanceSepolia)} ETH\n`) // 2. Query the network that the provider is connected to - const network1 = await provider1.getNetwork(); - const network2 = await provider2.getNetwork(); + const network1 = await providerETH.getNetwork(); + const network2 = await providerSepolia.getNetwork(); console.log("Network 1:", network1.name, "ID:", network1.chainId); console.log("Network 2:", network2.name, "ID:", network2.chainId); // 3. Query the block number const main = async () => { - const blockNumber = await provider1.getBlockNumber(); + const blockNumber = await providerETH.getBlockNumber(); console.log(blockNumber); // 4. Query the transaction count of vitalik's wallet const main = async () => { - const txcount = await provider1.getTransactionCount('vitalik.eth'); + const txcount = await providerETH.getTransactionCount('vitalik.eth'); console.log(txcount); // 5. Query the current suggested gas settings const main = async () => { - const feeData = await provider1.getFeeData(); + const feeData = await providerETH.getFeeData(); console.log(feeData); // 6. Query block information const main = async () => { - const block = await provider1.getBlock(0); + const block = await providerETH.getBlock(0); console.log(block); // 7. Query the bytecode of a given contract address, using WETH address as an example const main = async () => { - const bytecode = await provider1.getCode('0xc778417e063141139fce010982780140aa0cd5ab'); + const bytecode = await providerETH.getCode('0xc778417e063141139fce010982780140aa0cd5ab'); console.log(bytecode); }; diff --git a/en/02_Provider/readme.md b/en/02_Provider/readme.md index fba8f41..e78b670 100644 --- a/en/02_Provider/readme.md +++ b/en/02_Provider/readme.md @@ -32,7 +32,7 @@ The most commonly used provider in `ethers` is `jsonRpcProvider`, which allows u ### Creating an API Key for the Node Service Provider -First, you need to register and create an API Key on the website of the node service provider (e.g INFURA, ALCHEMY). In the "Tools" section of the "WTF Solidity" tutorial, we introduced the methods to create API Keys for two projects, Infura and Alchemy. You can refer to the tutorial for more information. +First, you need to register and create an API Key on the website of the node service provider (e.g [Infura](https://github.com/AmazingAng/WTFSolidity/blob/main/Topics/Tools/TOOL02_Infura/readme.md), [Alchemy](https://github.com/AmazingAng/WTFSolidity/blob/main/Topics/Tools/TOOL04_Alchemy/readme.md). In the "Tools" section of the "WTF Solidity" tutorial, we introduced the methods to create API Keys for two projects, Infura and Alchemy. You can refer to the tutorial for more information. ![Infura API Key](img/2-1.png) diff --git a/en/03_ReadContract/ReadContract.js b/en/03_ReadContract/ReadContract.js index ad0dd20..f8c17ba 100644 --- a/en/03_ReadContract/ReadContract.js +++ b/en/03_ReadContract/ReadContract.js @@ -2,7 +2,7 @@ // Parameters are the contract address `address`, contract `ABI`, Provider variable `provider` // const contract = new ethers.Contract(`address`, `ABI`, `provider`); -const { ethers } = require "ethers"; +import { ethers } from "ethers"; // Connect to the Ethereum network using the Infura RPC node const INFURA_MAINNET_URL = 'https://mainnet.infura.io/v3/8b9750710d56460d940aeff47967c4ba'; From 0df690d88457b190a4b72565f87fdb1ef6a4c30b Mon Sep 17 00:00:00 2001 From: murphyyue Date: Sat, 16 Mar 2024 15:36:09 +0800 Subject: [PATCH 6/7] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=8F=98=E9=87=8F?= =?UTF-8?q?=E9=87=8D=E5=A4=8D=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- en/03_ReadContract/ReadContract.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/en/03_ReadContract/ReadContract.js b/en/03_ReadContract/ReadContract.js index f8c17ba..463ae7f 100644 --- a/en/03_ReadContract/ReadContract.js +++ b/en/03_ReadContract/ReadContract.js @@ -38,22 +38,22 @@ const main = async () => { console.log(`Total Supply: ${ethers.formatEther(totalSupply)}`); const balanceAddress = 'vitalik.eth'; - const balance = await WETH_contract.balanceOf('vitalik.eth'); + const balance = await WETH_contract.balanceOf(balanceAddress); console.log(`Vitalik's Balance: ${ethers.formatEther(balance)}\n`); // 2. Reading on-chain information of the DAI contract (ERC20 interface contract) - const name = await DAI_contract.name(); - const symbol = await DAI_contract.symbol(); - const totalSupply = await DAI_contract.totalSupply(); + const nameDAI = await DAI_contract.name(); + const symbolDAI = await DAI_contract.symbol(); + const totalSupplyDAI = await DAI_contract.totalSupply(); console.log(`\nReading from ${DAI_address}\n`); - console.log(`Name: ${name}`); - console.log(`Symbol: ${symbol}`); - console.log(`Total Supply: ${ethers.formatEther(totalSupply)}`); + console.log(`Name: ${nameDAI}`); + console.log(`Symbol: ${symbolDAI}`); + console.log(`Total Supply: ${ethers.formatEther(totalSupplyDAI)}`); - const balanceAddress = 'vitalik.eth'; - const balance = await DAI_contract.balanceOf('vitalik.eth'); - console.log(`Vitalik's Balance: ${ethers.formatEther(balance)}\n`); + const balanceAddressDAI = "vitalik.eth"; + const balanceDAI = await DAI_contract.balanceOf(balanceAddressDAI); + console.log(`Vitalik's Balance: ${ethers.formatEther(balanceDAI)}\n`); }; main() From fb7d245a051fdb2ddd9e53c9341268a0372d8f12 Mon Sep 17 00:00:00 2001 From: murphyyue Date: Sun, 12 May 2024 21:46:25 +0800 Subject: [PATCH 7/7] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=89=80=E6=9C=89?= =?UTF-8?q?=E8=8B=B1=E6=96=87=E6=95=99=E7=A8=8B=E4=B8=AD`ethers`=E7=9A=84?= =?UTF-8?q?=E5=BC=95=E5=85=A5=E6=96=B9=E5=BC=8F=EF=BC=8C=E4=BB=8Erequire?= =?UTF-8?q?=E6=94=B9=E4=B8=BAimport?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- en/01_HelloVitalik/readme.md | 2 +- en/04_SendETH/SendETH.js | 4 ++-- en/04_SendETH/readme.md | 2 +- en/05_WriteContract/WriteContract.js | 2 +- en/05_WriteContract/readme.md | 2 +- en/06_DeployContract/DeployContract.js | 2 +- en/06_DeployContract/readme.md | 2 +- en/07_Event/Event.js | 2 +- en/07_Event/readme.md | 2 +- en/08_ContractListener/ContractListener.js | 2 +- en/08_ContractListener/readme.md | 2 +- en/10_Units/Units.js | 2 +- en/11_StaticCall/readme.md | 2 +- en/11_StaticCall/staticCall.js | 2 +- en/12_ERC721Check/ERC721Check.js | 2 +- en/13_EncodeCalldata/EncodeCalldata.js | 2 +- en/14_HDwallet/HDwallet.js | 2 +- en/15_MultiTransfer/MultiTransfer.js | 2 +- en/19_Mempool/Mempool.js | 2 +- en/21_VanityAddress/VanityAddress.js | 2 +- en/21_VanityAddress/readme.md | 2 +- en/26_EIP712/eip712.js | 2 +- 22 files changed, 23 insertions(+), 23 deletions(-) diff --git a/en/01_HelloVitalik/readme.md b/en/01_HelloVitalik/readme.md index cccf221..f62b0ed 100644 --- a/en/01_HelloVitalik/readme.md +++ b/en/01_HelloVitalik/readme.md @@ -66,7 +66,7 @@ Now, let's write our first program using `ethers` called `HelloVitalik`: it will ![Hello Vitalik](./img/1-4.png) ```javascript -const { ethers } = require("ethers"); +import { ethers } from "ethers"; const provider = new ethers.JsonRpcProvider(`NODE_URL`) //e.g ALCHEMY, INFURA const address = 'vitalik.eth' const main = async() => { diff --git a/en/04_SendETH/SendETH.js b/en/04_SendETH/SendETH.js index 5d5cdaa..9548865 100644 --- a/en/04_SendETH/SendETH.js +++ b/en/04_SendETH/SendETH.js @@ -1,5 +1,5 @@ // Send ETH using the Wallet class -const { ethers } = require("ethers"); +import { ethers } from "ethers"; // Connect to the Ethereum test network using the Infura or Alchemy RPC node const provider = new ethers.JsonRpcProvider(`https://sepolia.infura.io/v3/8b9750710d56460d940aeff47967c4ba`) @@ -7,7 +7,7 @@ const INFURA_SEPOLIA_URL = 'https://sepolia.infura.io/v3/8b9750710d56460d940aeff const provider = new ethers.JsonRpcProvider(INFURA_SEPOLIA_URL); // Send ETH using the Wallet class -const { ethers } = require("ethers"); +import { ethers } from "ethers"; // Connect to the Ethereum test network using the Infura or Alchemy RPC node const provider = new ethers.JsonRpcProvider(`https://sepolia.infura.io/v3/8b9750710d56460d940aeff47967c4ba`) diff --git a/en/04_SendETH/readme.md b/en/04_SendETH/readme.md index dc9d4f0..f780ee2 100644 --- a/en/04_SendETH/readme.md +++ b/en/04_SendETH/readme.md @@ -60,7 +60,7 @@ NB: For exercise purposes, connect a testnet address on your metamask with fauce ```javascript // Send ETH using the Wallet class -const { ethers } = require("ethers"); +import { ethers } from "ethers"; // Connect to the Ethereum test network using the Infura or Alchemy RPC node const provider = new ethers.JsonRpcProvider(`https://sepolia.infura.io/v3/8b9750710d56460d940aeff47967c4ba`) ``` diff --git a/en/05_WriteContract/WriteContract.js b/en/05_WriteContract/WriteContract.js index 60e5786..2b15f23 100644 --- a/en/05_WriteContract/WriteContract.js +++ b/en/05_WriteContract/WriteContract.js @@ -2,7 +2,7 @@ // const contract = new ethers.Contract(address, ABI, signer) // The parameters are the contract address `address`, contract ABI `abi`, and the signer variable `signer` -const { ethers } = require("ethers"); +import { ethers } from "ethers"; // The free version of playcode does not allow the installation of ethers. // Use this command to import the package from the web (comment out the line above) // import { ethers } from "https://cdn-cors.ethers.io/lib/ethers-5.6.9.esm.min.js"; diff --git a/en/05_WriteContract/readme.md b/en/05_WriteContract/readme.md index 2d2601e..20e7ef7 100644 --- a/en/05_WriteContract/readme.md +++ b/en/05_WriteContract/readme.md @@ -66,7 +66,7 @@ Here, `METHOD_NAME` is the name of the function to be called, `args` is the func 1. Create the `provider` and `wallet` variables. ```js - const { ethers } = require("ethers"); + import { ethers } from "ethers"; // Connect to the Ethereum network using Infura's RPC node const provider = new ethers.JsonRpcProvider(`https://sepolia.infura.io/v3/8b9750710d56460d940aeff47967c4ba`); diff --git a/en/06_DeployContract/DeployContract.js b/en/06_DeployContract/DeployContract.js index 2a01332..50dbc4a 100644 --- a/en/06_DeployContract/DeployContract.js +++ b/en/06_DeployContract/DeployContract.js @@ -6,7 +6,7 @@ // contractFactory.deploy(args) // Where args is the constructor parameters of the contract -const { ethers } = require("ethers"); +import { ethers } from "ethers"; // Connect to the Ethereum network using Infura's RPC node // Connect to the Sepolia test network diff --git a/en/06_DeployContract/readme.md b/en/06_DeployContract/readme.md index 471b906..2b59c46 100644 --- a/en/06_DeployContract/readme.md +++ b/en/06_DeployContract/readme.md @@ -57,7 +57,7 @@ For an introduction to the `ERC20` standard token contract, refer to the WTF Sol 1. Create `provider` and `wallet` variables. ```js - const { ethers } = require("ethers"); + import { ethers } from "ethers"; // Connect to the Ethereum network using Infura's RPC node // Connect to the Sepolia test network diff --git a/en/07_Event/Event.js b/en/07_Event/Event.js index 22526ad..af5aa78 100644 --- a/en/07_Event/Event.js +++ b/en/07_Event/Event.js @@ -2,7 +2,7 @@ // const transferEvents = await contract.queryFilter("Event Name", [Start Block Height, End Block Height]) // Start Block Height and End Block Height are optional parameters. -const { ethers } = require("ethers"); +import { ethers } from "ethers"; // Connect to the Ethereum network using Infura's RPC node // If you use a testnet, it may throw error "undefined", so mainnet is advisable. const INFURA_MAINNET_URL = 'https://mainnet.infura.io/v3/8b9750710d56460d940aeff47967c4ba' diff --git a/en/07_Event/readme.md b/en/07_Event/readme.md index 09dc715..88de4e4 100644 --- a/en/07_Event/readme.md +++ b/en/07_Event/readme.md @@ -57,7 +57,7 @@ const transferEvents = await contract.queryFilter('event name', starting block, 1. Create a `provider`. ```js - const { ethers } = require("ethers"); + import { ethers } from "ethers"; // Connect to the Ethereum network using Infura's RPC node const INFURA_MAINNET_URL = (`https://mainnet.infura.io/v3/8b9750710d56460d940aeff47967c4ba`); const provider = new ethers.JsonRpcProvider(INFURA_MAINNET_URL); diff --git a/en/08_ContractListener/ContractListener.js b/en/08_ContractListener/ContractListener.js index 5b1e43b..7567023 100644 --- a/en/08_ContractListener/ContractListener.js +++ b/en/08_ContractListener/ContractListener.js @@ -4,7 +4,7 @@ // 2. Listen only once // contractUSDT.once("event name", Listener) -const { ethers } = require("ethers"); +import { ethers } from "ethers"; // Connect to the mainnet provider const provider = new ethers.JsonRpcProvider(`https://mainnet.infura.io/v3/8b9750710d56460d940aeff47967c4ba`); diff --git a/en/08_ContractListener/readme.md b/en/08_ContractListener/readme.md index 20c70fd..cf49aeb 100644 --- a/en/08_ContractListener/readme.md +++ b/en/08_ContractListener/readme.md @@ -49,7 +49,7 @@ contract.once("eventName", function) 1. Declare the `provider`: Infura is a free ETH node provider. You need to apply for one before proceeding as we've established from Tutorial 1. [Apply here](app.infura.io). ```js - const { ethers } = require("ethers"); + import { ethers } from "ethers"; // Connect to the mainnet provider const provider = new ethers.JsonRpcProvider(`https://mainnet.infura.io/v3/8b9750710d56460d940aeff47967c4ba`); ``` diff --git a/en/10_Units/Units.js b/en/10_Units/Units.js index 5c1a537..a8fe79b 100644 --- a/en/10_Units/Units.js +++ b/en/10_Units/Units.js @@ -1,4 +1,4 @@ -const { ethers } = require("ethers"); +import { ethers } from "ethers"; // 1. BigNumber class console.group('\n1. BigNumber class'); diff --git a/en/11_StaticCall/readme.md b/en/11_StaticCall/readme.md index 8643734..68e890c 100644 --- a/en/11_StaticCall/readme.md +++ b/en/11_StaticCall/readme.md @@ -57,7 +57,7 @@ console.log(`Will the transaction succeed?`, tx) 1. Create `provider` and `wallet` objects. ```js - const { ethers } = require("ethers"); + import { ethers } from "ethers"; // Prepare Alchemy or Infura API, can refer to const provider = new ethers.JsonRpcProvider( "https://mainnet.infura.io/v3/8b9750710d56460d940aeff47967c4ba" diff --git a/en/11_StaticCall/staticCall.js b/en/11_StaticCall/staticCall.js index 2d9dc5b..826e4b0 100644 --- a/en/11_StaticCall/staticCall.js +++ b/en/11_StaticCall/staticCall.js @@ -1,4 +1,4 @@ -const { ethers } = require("ethers"); +import { ethers } from "ethers"; const provider = new ethers.JsonRpcProvider( "https://mainnet.infura.io/v3/8b9750710d56460d940aeff47967c4ba"); diff --git a/en/12_ERC721Check/ERC721Check.js b/en/12_ERC721Check/ERC721Check.js index 07cfdf5..12788b1 100644 --- a/en/12_ERC721Check/ERC721Check.js +++ b/en/12_ERC721Check/ERC721Check.js @@ -1,4 +1,4 @@ -const { ethers } = require("ethers"); +import { ethers } from "ethers"; const INFURA_MAINNET_URL = 'https://mainnet.infura.io/v3/8b9750710d56460d940aeff47967c4ba'; const provider = new ethers.JsonRpcProvider(INFURA_MAINNET_URL); diff --git a/en/13_EncodeCalldata/EncodeCalldata.js b/en/13_EncodeCalldata/EncodeCalldata.js index 799b493..385d066 100644 --- a/en/13_EncodeCalldata/EncodeCalldata.js +++ b/en/13_EncodeCalldata/EncodeCalldata.js @@ -3,7 +3,7 @@ // const interface = ethers.Interface(abi) // Get directly from the contract // const interface2 = contract.interface -const { ethers } = require("ethers"); +import { ethers } from "ethers"; const provider = new ethers.JsonRpcProvider( "https://sepolia.infura.io/v3/8b9750710d56460d940aeff47967c4ba" diff --git a/en/14_HDwallet/HDwallet.js b/en/14_HDwallet/HDwallet.js index 8134aa0..4fffb27 100644 --- a/en/14_HDwallet/HDwallet.js +++ b/en/14_HDwallet/HDwallet.js @@ -1,4 +1,4 @@ -const { ethers } = require("ethers"); +import { ethers } from "ethers"; // 1. Create HD wallet console.log("\n1. Create HD wallet") diff --git a/en/15_MultiTransfer/MultiTransfer.js b/en/15_MultiTransfer/MultiTransfer.js index 1ba6302..2f7dd59 100644 --- a/en/15_MultiTransfer/MultiTransfer.js +++ b/en/15_MultiTransfer/MultiTransfer.js @@ -1,4 +1,4 @@ -const { ethers } = require("ethers"); +import { ethers } from "ethers"; console.log("\n1. Create HD wallet") // Generate random mnemonic console.log("\n1. Create an HD wallet"); diff --git a/en/19_Mempool/Mempool.js b/en/19_Mempool/Mempool.js index 3926067..3f9b3f4 100644 --- a/en/19_Mempool/Mempool.js +++ b/en/19_Mempool/Mempool.js @@ -1,5 +1,5 @@ // provider.on("pending", listener) -const { ethers } = require("ethers"); +import { ethers } from "ethers"; // 1. Create provider and wallet, recommend using wss connection instead of http when listening for events console.log("\n1. Connecting to wss RPC") diff --git a/en/21_VanityAddress/VanityAddress.js b/en/21_VanityAddress/VanityAddress.js index 725975f..7b0ab8f 100644 --- a/en/21_VanityAddress/VanityAddress.js +++ b/en/21_VanityAddress/VanityAddress.js @@ -5,7 +5,7 @@ // Example: two 0 at the beginning and two 1 at the end // const regex = /^0x00.*11$/ -const { ethers } = require("ethers"); +import { ethers } from "ethers"; var wallet // Wallet const regex = /^0x000.*$/ // Expression var isValid = false diff --git a/en/21_VanityAddress/readme.md b/en/21_VanityAddress/readme.md index 9fceb4a..1e33ecc 100644 --- a/en/21_VanityAddress/readme.md +++ b/en/21_VanityAddress/readme.md @@ -65,7 +65,7 @@ isValid = regex.test(wallet.address) // Check the regular expression The logic of the vanity address generator is very simple. It continuously generates random wallets until it matches the desired vanity address. In our test, generating a vanity address starting with `0x000` takes only a few seconds, and each additional `0` increases the time by 16 times. ```js -const { ethers } = require("ethers"); +import { ethers } from "ethers"; var wallet // Wallet const regex = /^0x000.*$/ // Expression var isValid = false diff --git a/en/26_EIP712/eip712.js b/en/26_EIP712/eip712.js index a93b865..5d5901d 100644 --- a/en/26_EIP712/eip712.js +++ b/en/26_EIP712/eip712.js @@ -1,4 +1,4 @@ -const { ethers } = require("ethers"); +import { ethers } from "ethers"; // Connect to the Ethereum network using Infura or Alchemy's RPC endpoint const SEPOLIA_TESTNET_URL = 'https://sepolia.infura.io/v3/8b9750710d56460d940aeff47967c4ba';