From 75f2e82a3aa6a33a8f8c9cf4b6a822ea510f398a Mon Sep 17 00:00:00 2001 From: Alex992Y Date: Fri, 8 Mar 2024 23:58:50 +0000 Subject: [PATCH] Sepolia Testing with V20.11.0 testing with new network --- basic/01-web3js-deploy/README-cn.md | 32 +++++-------- basic/01-web3js-deploy/README.md | 2 + basic/02-web3js-transaction/README-cn.md | 32 +++++++------ basic/02-web3js-transaction/README.md | 26 ++++++---- basic/02-web3js-transaction/index.js | 8 ++-- basic/03-web3js-erc20/README-cn.md | 8 ++-- basic/03-web3js-erc20/README.md | 4 +- basic/03-web3js-erc20/index.js | 2 +- basic/04-web3js-truffle/README-CN.md | 27 +++++++---- basic/04-web3js-truffle/README.md | 16 +++++-- .../test/TestSimpleToken.sol | 1 + basic/04-web3js-truffle/test/simpletoken.js | 6 +-- basic/04-web3js-truffle/truffle-config.js | 47 +++++++------------ basic/05-ethersjs-erc20/index.js | 2 +- 14 files changed, 115 insertions(+), 98 deletions(-) diff --git a/basic/01-web3js-deploy/README-cn.md b/basic/01-web3js-deploy/README-cn.md index b2235013b..93ee1934e 100644 --- a/basic/01-web3js-deploy/README-cn.md +++ b/basic/01-web3js-deploy/README-cn.md @@ -14,6 +14,8 @@ https://ithelp.ithome.com.tw/articles/10202794 在成功创建 Infura Project - 同时在 BiliBili 上有上传本样例代码的讲解演示: https://www.bilibili.com/video/BV1Y44y1r7E6/ +--测试Node版本:v20.11.0 + ## 合约功能说明 constructor: 构造函数, 用于部署合约时调用, 同时在其中初始化了公共变量 number 的值 increment: 增值函数, 根据传入的数值 ( _value ), 对公共变量 number 进行增值 ( number + _value ) @@ -77,13 +79,13 @@ const input = { }, }; -const tempFile = JSON.parse(solc.compile(JSON.stringify(input))); +const compiledCode = JSON.parse(solc.compile(JSON.stringify(input))); ``` 3) 获取二进制对象 在上一步编译成功的 solidity 对象里面包含很多的属性/值, 而我们需要的是其中合约对象的二进制, abi 属性值. 如下, 我们通过属性提取方式进行获取. solidity 对象的其他属性可以通过代码调试方式进行调试, 这里不再赘述. ```js -const contractFile = tempFile.contracts["Incrementer.sol"]["Incrementer"]; +const contractFile = compiledCode.contracts["Incrementer.sol"]["Incrementer"]; // Get bin & abi const bytecode = contractFile.evm.bytecode.object; @@ -125,31 +127,21 @@ const deployContract = new web3.eth.Contract(abi); ```js // Create Tx const deployTx = deployContract.deploy({ - data: bytecode, - arguments: [5], + data: '0x' + bytecode, + arguments: [0], }); ``` -8) 交易签名 -如下使用私钥对交易进行签名, -```js -// Sign Tx -const deployTransaction = await web3.eth.accounts.signTransaction( - { - data: deployTx.encodeABI(), - gas: 8000000, - }, - account_from.privateKey -); -``` + 9) 部署合约 这里使用发送签名后的交易到区块链网络, 同时会去返回的交易回执. 从返回的交易回执中可以得到此次部署的合约的地址 ```js -const deployReceipt = await web3.eth.sendSignedTransaction( - deployTransaction.rawTransaction -); -console.log(`Contract deployed at address: ${deployReceipt.contractAddress}`); +const tx = await deployTx.send({ + from: accounts[0].address, + gas, + // gasPrice: 10000000000, +}); ``` ## 参考文档 diff --git a/basic/01-web3js-deploy/README.md b/basic/01-web3js-deploy/README.md index fd8fa80b4..7d6d76aef 100644 --- a/basic/01-web3js-deploy/README.md +++ b/basic/01-web3js-deploy/README.md @@ -27,6 +27,8 @@ Through this basic task, you can learn the processes of compiling and deploying - If you know Chinese, you can check these tasks on [BILIBILI](https://www.bilibili.com/video/BV1Y44y1r7E6/). +--Node Version:v20.11.0 + # Getting Started ## Understanding The Functions of the [Smart Contract](Incrementer.sol) diff --git a/basic/02-web3js-transaction/README-cn.md b/basic/02-web3js-transaction/README-cn.md index ba1287430..3d6ae4863 100644 --- a/basic/02-web3js-transaction/README-cn.md +++ b/basic/02-web3js-transaction/README-cn.md @@ -2,6 +2,8 @@ ## 前言 通过本样例代码,开发者了解到如何对交易进行签名,发送,接收交易回执,验证交易执行结果。同时,样例也提供了事件监听的逻辑代码,开发者可以了解如何对一个事件进行一次或多次监听 +--测试Node版本:v20.11.0 + ## 合约功能说明 constructor: 构造函数, 用于部署合约时调用, 同时在其中初始化了公共变量 number 的值 increment: 增值函数, 根据传入的数值 ( _value ), 对公共变量 number 进行增值 ( number + _value ) @@ -88,13 +90,13 @@ const privatekey = process.env.PRIVATE_KEY; 3) 构造 web3 对象 通过 web3 对象可以很方便的发送相应的交易到区块链网络, 同时获取区块链的处理结果. -构造 web3 对象时, 主要需要传入一个参数, 就是对应的区块链网络, 包括 goerli 测试网络, 或是 mainnet 主网. -这里我们使用 goerli 测试网络. 如果没有 goerli 网络的测试币, 可以切换到其他的测试网络. +构造 web3 对象时, 主要需要传入一个参数, 就是对应的区块链网络, 包括 sepolia 测试网络, 或是 mainnet 主网. +这里我们使用 sepolia 测试网络. 如果没有 sepolia 网络的测试币, 可以切换到其他的测试网络. 同时需要注意的是, 这里我们通过 infura 向对应的区块链网络发送交易, 而 INFURA_ID 这个变量值也需要配置在 .env 文件中, 具体如何获取 infura_id, 可自行搜索查找相关文档 ```js // Provider const providerRPC = { - development: "https://goerli.infura.io/v3/" + process.env.INFURA_ID, + development: "https://sepolia.infura.io/v3/" + process.env.INFURA_ID, moonbase: "https://rpc.testnet.moonbeam.network", }; const web3 = new Web3(providerRPC.development); //Change to correct network @@ -138,7 +140,7 @@ const deployTx = deployContract.deploy({ 如下使用私钥对交易进行签名, ```js // Sign Tx -const deployTransaction = await web3.eth.accounts.signTransaction( +const createReceipt = await web3.eth.accounts.signTransaction( { data: deployTx.encodeABI(), gas: 8000000, @@ -150,16 +152,16 @@ const deployTransaction = await web3.eth.accounts.signTransaction( 9) 部署合约 这里使用发送签名后的交易到区块量网络, 同时回去返回的交易回执. 从返回的交易回执中可以得到此次部署的合约的地址 ```js -const deployReceipt = await web3.eth.sendSignedTransaction( - deployTransaction.rawTransaction +const createReceipt = await web3.eth.sendSignedTransaction( + createTransaction.rawTransaction ); -console.log(`Contract deployed at address: ${deployReceipt.contractAddress}`); +console.log(`Contract deployed at address: ${createReceipt.contractAddress}`); ``` 10) 通过已经部署的合约地址加载合约实例 上述, 我们是先构造了一个合约实例, 然后再通过发送合约部署交易, 实现合约实例的上链, 以便后续进行相应的交易操作. 但同时, 我们也可以直接加载一个已经上链的合约实例, 这样就可以直接对合约进行操作, 避免了中间的部署过程 ```js -let incrementer = new web3.eth.Contract(abi, deployReceipt.contractAddress); +let incrementer = new web3.eth.Contract(abi, createReceipt.contractAddress); ``` 11) 调用合约只读接口 @@ -201,11 +203,9 @@ const incrementReceipt = await web3.eth.sendSignedTransaction( 如下, 在合约实例上调用 once 接口, 传入监听的事件为 "Increment", 就生成了一个一次性的事件监听器. 当有 "Increment" 触发时, 就会打印相应的提示信息 ```js const web3Socket = new Web3( - new Web3.providers.WebsocketProvider( - "wss://goerli.infura.io/ws/v3/0aae8358bfe04803b8e75bb4755eaf07" - ) + "wss://sepolia.infura.io/ws/v3/" ++ process.env.INFURA_ID ); - incrementer = new web3Socket.eth.Contract(abi, createReceipt.contractAddress); + // listen to Increment event only once incrementer.once("Increment", (error, event) => { @@ -219,6 +219,7 @@ const web3Socket = new Web3( incrementer.events.Increment(() => { console.log("I am a longlive event listner, I get a event now"); }); + #以上持续监听代码已更新,新的代码参考 index.js中 第171行 ~ 第184行 ``` - 触发事件 @@ -226,6 +227,7 @@ incrementer.events.Increment(() => { ```js let incrementTx = incrementer.methods.increment(_value); +//为了演示触发error的事件机制,index.js 中将上述 “_value”直接设定为0,触发'increment value should be positive number'事件 incrementTransaction = await web3.eth.accounts.signTransaction( { @@ -236,12 +238,14 @@ incrementTransaction = await web3.eth.accounts.signTransaction( account_from.privateKey ); - await web3.eth.sendSignedTransaction(incrementTransaction.rawTransaction); + await web3.eth + .sendSignedTransaction(incrementTransaction.rawTransaction) + .on('error', console.error) ``` ## 参考文章 代码参考文章如下 https://docs.moonbeam.network/getting-started/local-node/deploy-contract/ -goerli 测试网无法使用 http 进行 event 监听,需要使用 web3socket, 可参考如下文章 +sepolia 测试网无法使用 http 进行 event 监听,需要使用 web3socket, 可参考如下文章 https://medium.com/blockcentric/listening-for-smart-contract-events-on-public-blockchains-fdb5a8ac8b9a diff --git a/basic/02-web3js-transaction/README.md b/basic/02-web3js-transaction/README.md index 4eb2cbfbf..f0511e711 100644 --- a/basic/02-web3js-transaction/README.md +++ b/basic/02-web3js-transaction/README.md @@ -2,6 +2,8 @@ # Abstract The demo code provides developers with an overview of how to sign, send, and receive receipt of transactions, and verify the results of their execution. The sample also provides the event monitoring code so that the developer can understand how to listen to an event one or more times. +--Node Version:v20.11.0 + # Getting Started ## Understanding The Functions of the [Smart Contract](Incrementer.sol) @@ -86,7 +88,7 @@ const privatekey = process.env.PRIVATE_KEY; ```js // Provider const providerRPC = { - development: "https://goerli.infura.io/v3/" + process.env.INFURA_ID, + development: "https://sepolia.infura.io/v3/" + process.env.INFURA_ID, moonbase: "https://rpc.testnet.moonbeam.network", }; const web3 = new Web3(providerRPC.development); //Change to correct network @@ -124,13 +126,15 @@ const deployTx = deployContract.deploy({ data: bytecode, arguments: [5], }); + +#arguments: [5] -> incrementer.sol : function increment ``` ### 8. Sign the transaction Use your private key to sign the transaction. ```js // Sign Tx -const deployTransaction = await web3.eth.accounts.signTransaction( +const createTransaction = await web3.eth.accounts.signTransaction( { data: deployTx.encodeABI(), gas: 8000000, @@ -142,10 +146,10 @@ const deployTransaction = await web3.eth.accounts.signTransaction( ### 9. Send the transaction / Deploy your smart contract Send your `deploy` transaction to the blockchain. You will receive a receipt, and get this contract address from the receipt. ```js -const deployReceipt = await web3.eth.sendSignedTransaction( - deployTransaction.rawTransaction +const createReceipt = await web3.eth.sendSignedTransaction( + createTransaction.rawTransaction ); -console.log(`Contract deployed at address: ${deployReceipt.contractAddress}`); +console.log(`Contract deployed at address: ${createReceipt.contractAddress}`); ``` @@ -195,12 +199,14 @@ In the interfaces, you retrieve the corresponding internal information by trigge ```js const web3Socket = new Web3( new Web3.providers.WebsocketProvider( - 'wss://goerli.infura.io/ws/v3/' + process.env.INFURA_ID + 'wss://sepolia.infura.io/ws/v3/' + process.env.INFURA_ID )); -incrementer = new web3Socket.eth.Contract(abi, createReceipt.contractAddress); +#Web3 can intital without assign Provider("new Web3.providers.WebsocketProvider"), it also work. check index.js line 162 ``` -| goerli don't support http protocol to event listen, need to use websocket. More details , please refer to this [blog](https://medium.com/blockcentric/listening-for-smart-contract-events-on-public-blockchains-fdb5a8ac8b9a) + +#we use sepolia now, it you interest in goerli, view below : +| sepolia don't support http protocol to event listen, need to use websocket. More details , please refer to this [blog](https://medium.com/blockcentric/listening-for-smart-contract-events-on-public-blockchains-fdb5a8ac8b9a) #### Listen to Increment event only once ```js @@ -213,8 +219,10 @@ incrementer.once('Increment', (error, event) => { incrementer.events.Increment(() => { console.log("I am a longlive event listener, I get a event now"); }); + +# event continuously code already change in index.js: from line 171~184, but above code also work. ``` # References - Code part: https://docs.moonbeam.network/getting-started/local-node/deploy-contract/ -- web3socket of Goerli: https://medium.com/blockcentric/listening-for-smart-contract-events-on-public-blockchains-fdb5a8ac8b9a \ No newline at end of file +- web3socket of sepolia: https://medium.com/blockcentric/listening-for-smart-contract-events-on-public-blockchains-fdb5a8ac8b9a \ No newline at end of file diff --git a/basic/02-web3js-transaction/index.js b/basic/02-web3js-transaction/index.js index 5ce9a694d..da003312b 100644 --- a/basic/02-web3js-transaction/index.js +++ b/basic/02-web3js-transaction/index.js @@ -14,7 +14,7 @@ function sleep(ms) { */ // Provider const providerRPC = { - development: 'https://goerli.infura.io/v3/' + process.env.INFURA_ID, + development: 'https://sepolia.infura.io/v3/' + process.env.INFURA_ID, moonbase: 'https://rpc.testnet.moonbeam.network', }; const web3 = new Web3(providerRPC.development); //Change to correct network @@ -49,7 +49,7 @@ const Trans = async () => { data: bytecode, arguments: [5], }); - + // Sign Tx const createTransaction = await web3.eth.accounts.signTransaction( { @@ -156,10 +156,10 @@ const Trans = async () => { console.log('============================ 5. Listen to Events'); console.log(' Listen to Increment Event only once && continuouslly'); - // goerli don't support http protocol to event listen, need to use websocket + // sepolia don't support http protocol to event listen, need to use websocket // more details , please refer to https://medium.com/blockcentric/listening-for-smart-contract-events-on-public-blockchains-fdb5a8ac8b9a const web3Socket = new Web3( - 'wss://goerli.infura.io/ws/v3/' + process.env.INFURA_ID + 'wss://sepolia.infura.io/ws/v3/' + process.env.INFURA_ID ); // listen to Increment event only once diff --git a/basic/03-web3js-erc20/README-cn.md b/basic/03-web3js-erc20/README-cn.md index f70e4f2c4..f573570b1 100644 --- a/basic/03-web3js-erc20/README-cn.md +++ b/basic/03-web3js-erc20/README-cn.md @@ -4,6 +4,8 @@ 本样例演示了 ERC20 合约的基本调用, 让开发者了解 ERC20 合约的基本接口 +--测试Node版本:v20.11.0 + ## SimpleToken 合约功能说明 - IERC20 @@ -119,12 +121,12 @@ 4. 构造 web3 对象 通过 web3 对象可以很方便的发送相应的交易到区块链网络, 同时获取区块链的处理结果. - 构造 web3 对象时, 主要需要传入一个参数, 就是对应的区块链网络, 包括 goerli 等测试网络, 或是 mainnet 主网. - 这里我们使用 goerli 测试网络. 如果没有 goerli 网络的测试币, 可以切换到其他的测试网络. + 构造 web3 对象时, 主要需要传入一个参数, 就是对应的区块链网络, 包括 sepolia 等测试网络, 或是 mainnet 主网. + 这里我们使用 sepolia 测试网络. 如果没有 sepolia 网络的测试币, 可以切换到其他的测试网络. 同时需要注意的是, 这里我们通过 infura 向对应的区块链网络发送交易, 而 INFURA_ID 这个变量值也需要配置在 .env 文件中, 具体如何获取 infura_id, 可自行搜索查找相关文档 ```js - const web3 = new Web3(new Web3.providers.HttpProvider('https://goerli.infura.io/v3/' + process.env.INFURA_ID)); + const web3 = new Web3(new Web3.providers.HttpProvider('https://sepolia.infura.io/v3/' + process.env.INFURA_ID)); ``` 5. 获取账户地址 diff --git a/basic/03-web3js-erc20/README.md b/basic/03-web3js-erc20/README.md index e7e3fdd55..f28641da5 100644 --- a/basic/03-web3js-erc20/README.md +++ b/basic/03-web3js-erc20/README.md @@ -4,6 +4,8 @@ This basic task is to show how to interact with ERC20 contract, so the developer can understand the basic interface of ERC20 contract. +--Node Version:v20.11.0 + ## Getting started ### SimpleToken contract function description @@ -113,7 +115,7 @@ const receiver = '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'; 4. Build the `web3` object ```js -const web3 = new Web3(new Web3.providers.HttpProvider('https://goerli.infura.io/v3/' + process.env.INFURA_ID)); +const web3 = new Web3(new Web3.providers.HttpProvider('https://sepolia.infura.io/v3/' + process.env.INFURA_ID)); ``` | Note: The `INFURA_ID` is the `PROJECT ID` of the `Infura` project you created in last [task](../01-web3js-deploy/README.md) diff --git a/basic/03-web3js-erc20/index.js b/basic/03-web3js-erc20/index.js index 473a9f4dc..45a293623 100644 --- a/basic/03-web3js-erc20/index.js +++ b/basic/03-web3js-erc20/index.js @@ -13,7 +13,7 @@ const receiver = '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'; // Provider const web3 = new Web3( new Web3.providers.HttpProvider( - 'https://goerli.infura.io/v3/' + process.env.INFURA_ID + 'https://sepolia.infura.io/v3/' + process.env.INFURA_ID ) ); diff --git a/basic/04-web3js-truffle/README-CN.md b/basic/04-web3js-truffle/README-CN.md index c680e6e76..77705c47a 100644 --- a/basic/04-web3js-truffle/README-CN.md +++ b/basic/04-web3js-truffle/README-CN.md @@ -17,6 +17,8 @@ truffle 开发框架提供了很多功能,简化了我们的开发、编译、 - 可配的构建流程,支持持续集成。 - 支持外部脚本的执行 +--Node Version:v20.11.0 + ## 文件说明 ### 目录结构 @@ -85,16 +87,18 @@ Writing artifacts to .\build\contracts 5. 部署合约 在 truffle-config.js 里面,可以配置 truffle 使用的以太网络,其中就包括 truffle test 使用的 "test" 网络。 -这里,直接执行 truffle migrate 报没有找到 test 网络,因为 truffle 不会启动内置的 test 网络。所以这里我们使用 goerli 进行 truffle 合约部署 +这里,直接执行 truffle migrate 报没有找到 test 网络,因为 truffle 不会启动内置的 test 网络。所以这里我们使用 sepolia 进行 truffle 合约部署 ```bash -truffle migrate --network goerli +truffle migrate --network sepolia +#确保你的sepolia 测试币不低于0.6 + ``` 当多次执行 truffle migrate 的时候,可能会出 "Network update to date", 然后不执行合约部署的情况,这个时候需要执行如下的 truffle 命令 ```bash -truffle migrate --network goerli --reset +truffle migrate --network sepolia --reset ``` ## 在 infura 测试合约 @@ -104,7 +108,9 @@ sol 的测试文件会报失败。所以,这里我们连接到 infura 进行 ```bash -truffle test ./test/simpletoken.js --network goerli +truffle test ./test/simpletoken.js --network sepolia + +#Warning 不影响交易可忽略 ``` ## 在本地测试合约 @@ -141,15 +147,15 @@ Private Keys: ``` -选择任意一个私钥,将其放置在 truffle-config.js 中 mnemonic 变量中。 +选择任意一个私钥,将其放置在 simpletoken.js 中 第21行 例如,原代码是 -- const mnemonic = fs.readFileSync('./sk.txt').toString().trim() +- const target = "0x5df22be367b95788cd51c7dbdf7c7ab70fe856ee"; + +将地址改成本机测试账户 -修改后的代码是 -- const mnemonic = "0a8d9e2a470aedfabe279f16f629c5054a47d69b7d66d17ba65cdd7ca99876e1" 接下来配置本地网络参数,将下面 network 属性中 development 注释打开,host 配置成本地,port 配置成 truffle develop 给出的端口地址,如本例中端口是 9545。network_id 保留原状。 @@ -163,6 +169,7 @@ Private Keys: 配置好以后即可运行 truffle compile 进行编译,truffle migrate 进行部署,truffle test 进行测试 + ```bash > Artifacts written to C:\Users\Highland\AppData\Local\Temp\test--33840-ApHyOzehxOdp > Compiled successfully using: @@ -181,6 +188,7 @@ Private Keys: 4 passing (32s) +#退出 develop模式,输入 .exit <--注意不要忘记 . ``` ## 使用 Truffle Dashboard 工具 @@ -214,7 +222,10 @@ dashboard 默认运行在 http://localhost:24012, 若不小心关闭了之前弹 dashboard 服务开启之后,truffle 会内置一个名为 dashboard 的网络。我们后续的部署和脚本运行都可以使用这个网络,例如 ```bash +#开启另外一个终端,重新进入本目录,truffle develop进入开发模式,再输入以下命令 > truffle migrate --network dashboard + +#.exit 退出开发模式,然后再输入以下命令,重新进入dashboard console模式 > truffle console --network dashboard ``` diff --git a/basic/04-web3js-truffle/README.md b/basic/04-web3js-truffle/README.md index db7006e0a..eee2e71de 100644 --- a/basic/04-web3js-truffle/README.md +++ b/basic/04-web3js-truffle/README.md @@ -13,6 +13,8 @@ - Configurable build pipeline with support for tight integration. - External script runner that executes scripts within a Truffle environment. +--Node Version:v20.11.0 + ### [Truffle Quickstart](https://www.trufflesuite.com/docs/truffle/quickstart) ## Introduction about Project @@ -81,17 +83,21 @@ In `truffle-config.js`, we can specify truffle to use the eth test network. However, after running `trffle migrate`, it reported there is no test network, so truffle didn't launch the built-in test network. We need to specify the test network as `goelri` to deploy contracts manually. ```bash - truffle migrate --network goerli + truffle migrate --network sepolia + #make sure your sepolia test token higher than 0.6 ``` - > If we run `truffle migrate` frequently, it may shows `Network update to date` and doesn't deploy the contracts. At that time, we need to run `truffle migrate --network goerli --reset` to reset the migration status. + > If we run `truffle migrate` frequently, it may shows `Network update to date` and doesn't deploy the contracts. At that time, we need to run `truffle migrate --network sepolia --reset` to reset the migration status. ## Test contracts on Infura Under `test` folder, there are two types, `sol` and `js`. `Truffle` supports both types, but if we use `infura`, we can't run `sol` file. So we only use `js` file as our test file. ```bash -truffle test ./test/simpletoken.js --network goerli +truffle test ./test/simpletoken.js --network sepolia + +#If the prompt is “Error: Cannot find module '/ Uws_darwin-arm64_115. node '”, nvm use v16. x.x, switch to any v16 version, and then execute this command +#Warning does not affect transactions and can be ignored ``` ## Test in local @@ -170,6 +176,7 @@ After finish the above steps, we can run `truffle compile`, `truffle migrate` an 4 passing (32s) +#Exit the develop mode and enter. exit<-- be careful not to forget ``` @@ -209,7 +216,10 @@ After you started the dashboard service, truffle will launch a network named `da ```bash +#Open another terminal, re-enter this directory, truffle develop into development mode, and then enter the following command > truffle migrate --network dashboard + +#Exit development mode with. exit, then enter the following command to re-enter dashboard console mode > truffle console --network dashboard ``` diff --git a/basic/04-web3js-truffle/test/TestSimpleToken.sol b/basic/04-web3js-truffle/test/TestSimpleToken.sol index 6687e51a8..812f575d1 100644 --- a/basic/04-web3js-truffle/test/TestSimpleToken.sol +++ b/basic/04-web3js-truffle/test/TestSimpleToken.sol @@ -1,3 +1,4 @@ +// SPDX-License-Identifier: UNLICENSED pragma solidity >=0.4.25 <=0.8.0; import "truffle/Assert.sol"; diff --git a/basic/04-web3js-truffle/test/simpletoken.js b/basic/04-web3js-truffle/test/simpletoken.js index c95249cc9..d9d404a0a 100644 --- a/basic/04-web3js-truffle/test/simpletoken.js +++ b/basic/04-web3js-truffle/test/simpletoken.js @@ -1,7 +1,7 @@ const SimpleToken = artifacts.require('SimpleToken') contract('SimpleToken', (accounts) => { - it(`Should put 100000 to the ${accounts[0]}`, async () => { + it(`Should put 100000 to the ${accounts[0]} `, async () => { const simpleTokenIns = await SimpleToken.deployed(); const balance = ( await simpleTokenIns.balanceOf.call(accounts[0]) @@ -10,7 +10,7 @@ contract('SimpleToken', (accounts) => { assert.equal( balance, 100000, - `the balance of ${accounts[0]} wasn not 100000` + `the balance of ${accounts[0]} } wasn not 100000` ); }); @@ -18,7 +18,7 @@ contract('SimpleToken', (accounts) => { it('Transfer 100 to other account', async () => { const simpleTokenIns = await SimpleToken.deployed(); - const target = "0x5df22be367b95788cd51c7dbdf7c7ab70fe856ee"; + const target = "0x96c94cedf3bed5ad0a31636fd6a5a64d2c2e2475"; // transfer 1000 to other account await simpleTokenIns.transfer(target, 1000); diff --git a/basic/04-web3js-truffle/truffle-config.js b/basic/04-web3js-truffle/truffle-config.js index 5b3051453..067f436a1 100644 --- a/basic/04-web3js-truffle/truffle-config.js +++ b/basic/04-web3js-truffle/truffle-config.js @@ -1,5 +1,6 @@ const fs = require('fs') const HDWalletProvider = require('truffle-hdwallet-provider') +const mnemonic = "35b08a65b9269c23c470963bc3203778e1c20d49f91e4b98b48fc6cf02575a33" require('dotenv').config(); @@ -16,44 +17,28 @@ module.exports = { }, }, networks: { - // development: { - // host: "127.0.0.1", - // port: 7545, - // network_id: "*" - // }, + development: { + host: "127.0.0.1", + port: 9545, + network_id: "*" + }, // test: { // host: "127.0.0.1", // port: 7545, // network_id: "*" // } //}, - ropsten: { - provider: () => - new HDWalletProvider( - process.env.PRIVATE_KEY, - 'https://ropsten.infura.io/v3/' + process.env.INFURA_ID - ), - network_id: '*', - gas: 3000000, - gasPrice: 10000000000, - }, - kovan: { - provider: () => - new HDWalletProvider( - process.env.PRIVATE_KEY, - 'https://kovan.infura.io/v3/' + process.env.INFURA_ID - ), - network_id: '*', - }, - rinkeby: { + + sepolia: { + networkCheckTimeout: 10000, provider: () => - new HDWalletProvider( - process.env.PRIVATE_KEY, - 'https://rinkeby.infura.io/v3/' + process.env.INFURA_ID - ), + new HDWalletProvider( + process.env.PRIVATE_KEY, + 'https://sepolia.infura.io/v3/' + process.env.INFURA_ID + ), network_id: '*', - gas: 3000000, + gas: 30000000, gasPrice: 10000000000, - }, + }, }, -} +} \ No newline at end of file diff --git a/basic/05-ethersjs-erc20/index.js b/basic/05-ethersjs-erc20/index.js index c0f5522db..b73fac543 100644 --- a/basic/05-ethersjs-erc20/index.js +++ b/basic/05-ethersjs-erc20/index.js @@ -23,7 +23,7 @@ const providerRPC = { }, }; const provider = new ethers.providers.InfuraProvider( - 'goerli', + 'sepolia', process.env.INFURA_ID ); //Change to correct network