Skip to content

Instantly share code, notes, and snippets.

@khssnv
Created May 27, 2018 06:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save khssnv/4afc185c94379465e2fdaa4ee95be8bd to your computer and use it in GitHub Desktop.
Save khssnv/4afc185c94379465e2fdaa4ee95be8bd to your computer and use it in GitHub Desktop.
Ethereum Ropsten last block number from Infura to HTTP at localhost
# -*- coding: utf-8
from web3 import Web3
from flask import Flask, request
from flask_restful import Resource, Api
from flask.json import jsonify
app = Flask(__name__)
api = Api(app)
with open('../secrets/infura_api.key', 'r') as f:
apikey = f.readline()
w3 = Web3(Web3.HTTPProvider('https://ropsten.infura.io/' + apikey))
class BlockNumber(Resource):
def get(self):
return jsonify({'blockNumber': w3.eth.blockNumber})
api.add_resource(BlockNumber, '/blockNumber')
if __name__ == '__main__':
app.run(port='5002')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment