test.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. from web3 import Web3
  2. import json
  3. import ipfshttpclient
  4. import pprint
  5. from web3.gas_strategies.time_based import medium_gas_price_strategy, fast_gas_price_strategy
  6. #infura_url_mainnet = "https://mainnet.infura.io/v3/88df052c847f4d80b839a6cdd00a515c"
  7. infura_kovan = "https://kovan.infura.io/v3/88df052c847f4d80b839a6cdd00a515c"
  8. # ganache_url = "http://127.0.0.1:7545"
  9. print("Connecting to Ethereum Test Network...")
  10. web3 = Web3(Web3.HTTPProvider(infura_kovan))
  11. # web3.eth.defaultAccount = web3.eth.accounts[0] #local
  12. web3.eth.defaultAccount = "0x92582427Bc16dEE757a20265F34460E13Fb05409"
  13. private_key = "c41170d8d93fb438f3a910d4a079d5e2140b55958c8f136b816c29280b2ed43d"
  14. print(f"Connected to Blockchain Test Network? {web3.isConnected()}")
  15. balance = web3.fromWei(web3.eth.getBalance(web3.eth.defaultAccount), 'ether')
  16. balance2 = web3.fromWei(web3.eth.getBalance(web3.eth.defaultAccount), 'gwei')
  17. print(balance)
  18. print(balance2)
  19. # web3.eth.setGasPriceStrategy(fast_gas_price_strategy)
  20. # gasprice = web3.eth.generateGasPrice()
  21. # gasprice2 = web3.fromWei(gasprice, 'gwei')
  22. # print(" gas price in wei", gasprice)
  23. # print(" gas price in gwei", gasprice2)
  24. gas_estimate = 25000
  25. gas_limit = gas_estimate + (gas_estimate * 0.1)
  26. print (gas_limit)
  27. # print(f'Gas estimate to transact with store function: {gas_estimate}')
  28. # transaction_cost = gasprice2 * gas_estimate
  29. # print(f'Transaction cost estimate: {transaction_cost} gwei')
  30. # if (balance2 > transaction_cost):
  31. # print("transaction can be done")
  32. # else:
  33. # print("not enough balance")