使用工具:remix、vscode、ganache、ethers.js、metamask、nodejs、solidity语言、 网页控制台、终端命令行
web3开发:前端开发 ethers.js
web3开发:前端使用ethers.js调用Hello智能合约。
hello.sol 智能合约文件:
// SPDX-License-Identifier: MIT pragma solidity 0.8.0; contract Hello { function greet() external pure returns(string memory) { return "Hello web3"; } }
dapp.html 前端文件:
<html> <head> <script src="https://cdn.ethers.io/lib/ethers-5.2.umd.min.js" type="text/javascript"></script> <script src="./contract.js" type="text/javascript"></script> </head> <body> <div style="text-align:center"> <div style="text-align: center; margin-top: 30px;"> <button οnclick="connectWallet()">Connect Wallet</button> <button οnclick="runContr