Fuxi v2.0.7
This release runs on testnets only and fixed the issue of parameters in eth_subscribe method.
Now the VNODE will support all four parameters in eth_subscribe method:
- newHeads
- logs
- newPendingTransactions
- syncing
To enable the JSON-RPC notifications, VNODE client needs to start with ws options.
For example, using the following parameters instead of "rpc".
moac --testnet --ws --wsaddr 0.0.0.0 --wsport 8546 --wsapi "chain3,mc,net,db,personal" --wsorigins "*"
本次发布版本仅用于测试网络,修复了eth_subscribe接口中支持参数的问题,使得用户可以在提供websocket接口的客户端订阅信息。
目前可以订阅的信息包括:
- newHeads
- logs
- newPendingTransactions
- syncing
为了使用订阅功能,需要VNODE客户端在启动时候使用"ws"选项:
moac --testnet --ws --wsaddr 0.0.0.0 --wsport 8546 --wsapi "chain3,mc,net,db,personal" --wsorigins "*"
然后,在web3中使用订阅功能
const Web3 = require('web3')
const web3 = new Web3("wss://localhost:8546")
function newBlockHeaders(){
var subscription = eth.subscribe('newBlockHeaders', function(error, result){
if (!error){
console.log(result);
}else{
console.log(error);
}
})
.on("data", function(transaction){
console.log(`transaction:${transaction}`);
})
}
// Start listening to different events
newBlockHeaders();