The other day I got myself in a situation where I needed to communicate with the Ethereum network using python in an environment where getting web3.py to work seemed pretty much impossible. Since I still needed to talk to the network, I resorted to using the JSON-RPC API provided by Ethereum, which all web3 libraries are built on top of. Turns out, it’s pretty interesting! So, let’s get started! Basic setup First things first — let’s declare a few variables that will be helpful when sending requests later: requests json session = requests.Session() url = headers = { : } import import "https://ropsten.infura.io/v3/YOUR_INFURA_KEY" 'Content-type' 'application/json' To keep things simple, we use an Infura Node to connect to the Ethereum Ropsten Testnet. You can get an API Key for that . here Your first Request Let’s get our feet wet by fetching the current gas price of the network. We can do this by simply doing: data = { : , : , : [], : } response = session.post(url, json=data, headers=headers) response.ok: gasPriceHex = response.json().get( ) gasPriceDecimal = int(gasPriceHex, ) : print( ) # Prepare the data we will send "jsonrpc" "2.0" "method" "eth_gasPrice" "params" "id" 1 # Check if response is valid if # Get result of the request and decode it to decimal "result" 16 else # Handle Error "Error occured" How did I know what method to use and what parameters to send? It can all be found in the official Ethereum docs. Getting the latest Block Let’s try something a bit more interesting — let’s fetch the latest block and see what we can read from there! blockNumber = fullTrx = params = [ blockNumber, fullTrx] data = { : , : , : params, : } response = session.post(url, json=data, headers=headers) response.ok: block = response.json().get( ) transactions = block.get( ) : # Set params and prepare data "latest" # Boolean indicating if we want the full transactions (True) or just their hashes (false) False "jsonrpc" "2.0" "method" "eth_getBlockByNumber" "params" "id" 1 # Check if response is valid if # Get the block "result" # Get the transactions contained in the block "transactions" else # Handle Error Let’s have a closer look at one of the transactions: params = [transactions[ ]] data = { : , : , : params, : } response = session.post(url, json=data, headers=headers) response.ok: transaction = response.json().get( ) : print( ) 0 "jsonrpc" "2.0" "method" "eth_getTransactionByHash" "params" "id" 3 if "result" else # Handle Error "Error occured" You’re probably starting to get the pattern of how these calls work, so let’s try something a little more advanced: Sending Transactions First, let’s create a new account using the web3.py library and load it with some Ropsten ether. I like to use . this faucet web3 w3 = web3.Web3() account = w3.eth.account.create( ) address = account.address pKey = account.privateKey import 'put any phrase here' To send create a transaction, we need the nonce. This too we can fetch with the RPC JSON API using the same pattern as above: params = [address, ] data = { : , : , : params, : } response = session.post(url, json=data, headers=headers) response.ok: nonce = response.json().get( ) : print( ) # Get the nonce at the latest block "latest" "jsonrpc" "2.0" "method" "eth_getTransactionCount" "params" "id" 3 if "result" else # Handle Error "Error occured" Next, we create and sign our transaction and send it off using the JSON RPC API once more: signed_txn = w3.eth.account.signTransaction({ : , : nonce, : gasPriceHex, : , : w3.toWei( , ), : , }, pKey) # Create our transaction # Faucet address 'to' '0x687422eEA2cB73B5d3e242bA5456b782919AFc85' 'nonce' 'gasPrice' 'gas' 100000 'value' 0.5 'ether' # 3 Because we are on Ropsten 'chainId' 3 If you’re testing on a different Ethereum (Test)net, make sure to set the chain Id accordingly. params = [signed_txn.rawTransaction.hex()] data = { : , : , : params, : } response = session.post(url, json=data, headers=headers) response.ok: receipt = response.json().get( ) : print( ) "jsonrpc" "2.0" "method" "eth_sendRawTransaction" "params" "id" 4 if "result" else # Handle Error "Error occured" Notice how we were able to reuse the gas price which we fetched at the beginning. Conclusion And that’s all! You just learned the basics of interacting with the most influential blockchain in the world using the ! You can find the code for all this . JSON RPC Ethereum API here Thanks for following along! Nicolas If you liked this, give this story a couple of reactions so more people can see it! If you LOVED this, buy me a coffee :) Ethereum: 0x190d71ba3738f43dc6075f5561e58ac9d4e3dfc2 Bitcoin: 1BRucWzs2vnrkfmbfss14ZQErW74A1H1KE Litecoin: LbNfoJfTFVCj7GFaAUtWqhitHJcJ3m8y3V