Skip to content

newyear6565/eth_event

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

event——订阅指定的合约事件

  • 此案例基于web3.js 1.0版本,可实现对合约中event的监听。

实现步骤

1.修改geth启动参数

geth --datadir ./data --networkid 15 --port 30303 --rpc --rpcaddr 0.0.0.0 --rpcport 8545 --rpcvhosts "*" --rpcapi 'db,net,eth,web3,personal' --rpccorsdomain "*" --ws --wsaddr "localhost" --wsport "8546" --wsorigins "*" --nat "any" --nodiscover --dev --dev.period 1 console 2> 1.log

  • 重点在于增加了下列参数
--ws --wsaddr "localhost" --wsport "8546" --wsorigins "*"

2.部署map.sol合约到geth上

  • 合约见map.sol

3.编写用于监听合约event的js文件

  • map_event.js

4.运行map_event.js监听event

npm init -y
npm install web3 --save
node map_event.js

5.调用map合约触发event

  • 监听效果

image

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%