-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwallet.py
33 lines (26 loc) · 867 Bytes
/
wallet.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import requests
from web3 import Web3
class Wallet:
balance: int
nonce: int
def __init__(self, web3: Web3, address: str, private_key: str):
self.web3 = web3
self.privateKey = private_key
self.address = address
self.refresh_nonce()
self.refresh_balance()
def refresh_nonce(self) -> int:
try:
self.nonce = self.web3.eth.get_transaction_count(self.address)
except requests.exceptions.ConnectionError:
pass
return self.nonce
def refresh_balance(self) -> float:
try:
self.balance = self.web3.from_wei(self.web3.eth.get_balance(self.address), 'ether')
except requests.exceptions.ConnectionError:
pass
except requests.exceptions.HTTPError as e:
print(e)
pass
return self.balance