Appearance
前言
Web3.js
是一组代码库,允许开发者通过HTTP
、IPC
或WebSocker
与以太坊节点交互。
环境准备
Nodejs v18.16.0 | Web3.js 1.8.0 |
---|
安装 web3@1.8.0
bash
npm install web3@1.8.0
获取 web3 对象
js
let Web3 = require("web3")
let web3 = new Web3(new Web3.providers.HttpProvider("HTTP://127.0.0.1:8545"))
console.log(web3)
输出
这会输出节点信息
bash
Web3 {
currentProvider: [Getter/Setter],
_requestManager: RequestManager {
provider: HttpProvider {
withCredentials: false,
timeout: 0,
headers: undefined,
agent: undefined,
connected: false,
host: 'HTTP://127.0.0.1:8545',
httpAgent: [Agent]
},
...