Use Python
- An Ethereum account containing some Goerli test ETH.
Create a new directory:
mkdir infura
cd
into the directory:cd infura
pip install web3
pip install python-dotenv
Add your private key to the
.env
file.SIGNER_PRIVATE_KEY = <PRIVATE-KEY>
Never disclose your private key.
A malicious actor who has access to your private key can steal your assets.
Replace
from_account
and to_account
with the relevant details.import os
from dotenv import load_dotenv
from web3 import Web3
load_dotenv()
infura_url = "https://goerli.infura.io/v3/<API-KEY>"
private_key = os.getenv('PRIVATE_KEY')
from_account = '0xeF8692168D0C165488ae3F0105Fe096f5E81820b'
to_account = '0x37d1215743ACf59B85f2DDE7Ab103f2BBC5a568F'
web3 = Web3(Web3.HTTPProvider(infura_url))
nonce = web3.eth.getTransactionCount(from_account)
tx = {
'type': '0x2',
'nonce': nonce,
'from': from_account,
'to': to_account,
'value': web3.toWei(0.01, 'ether'),
'maxFeePerGas': web3.toWei('250', 'gwei'),
'maxPriorityFeePerGas': web3.toWei('3', 'gwei'),
'chainId': 3
}
gas = web3.eth.estimateGas(tx)
tx['gas'] = gas
signed_tx = web3.eth.account.sign_transaction(tx, private_key)
tx_hash = web3.eth.send_raw_transaction(signed_tx.rawTransaction)
print("Transaction hash: " + str(web3.toHex(tx_hash)))
If using a different Ethereum network, update the URL in the script.
Run the script:
python eip1559_tx.py
Example output:
Transaction hash: 0x30c0ef29111ca7aecc78a99149649b5076d104afa7ed2f603ff2d2ec1aa27a8c
Last modified 6mo ago