From 280bb33bc043be39242acba943ee5d941801ad7d Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Sat, 27 Jul 2024 06:55:49 +0700 Subject: [PATCH] Create Web3.js --- .../pi-network-interoperability/utils/Web3.js | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 blockchain_integration/pi_network/pi-network-interoperability/utils/Web3.js diff --git a/blockchain_integration/pi_network/pi-network-interoperability/utils/Web3.js b/blockchain_integration/pi_network/pi-network-interoperability/utils/Web3.js new file mode 100644 index 000000000..2b4a99594 --- /dev/null +++ b/blockchain_integration/pi_network/pi-network-interoperability/utils/Web3.js @@ -0,0 +1,29 @@ +const Web3 = require('web3'); + +class Web3Utils { + constructor(providerUrl) { + this.web3 = new Web3(new Web3.providers.HttpProvider(providerUrl)); + } + + async getBlockNumber() { + return this.web3.eth.getBlockNumber(); + } + + async getTransactionCount(address) { + return this.web3.eth.getTransactionCount(address); + } + + async getBalance(address) { + return this.web3.eth.getBalance(address); + } + + async sendTransaction(tx) { + return this.web3.eth.sendTransaction(tx); + } + + async getTransactionReceipt(txHash) { + return this.web3.eth.getTransactionReceipt(txHash); + } +} + +module.exports = Web3Utils;