Last active
August 1, 2023 12:59
-
-
Save jsvisa/543bfe57a4a3c95a5090a2aedb4ca166 to your computer and use it in GitHub Desktop.
send gasPrice 0 tx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import argparse | |
import logging | |
from web3 import Web3, HTTPProvider | |
logging.basicConfig( | |
format="[%(asctime)s] - %(levelname)s - %(message)s", level=logging.INFO | |
) | |
def main(): | |
parser = argparse.ArgumentParser( | |
formatter_class=argparse.ArgumentDefaultsHelpFormatter, | |
description="Send ethereum transaction", | |
) | |
parser.add_argument( | |
"--provider", | |
default="http://127.0.0.1:8545", | |
help="Web3 provider", | |
) | |
parser.add_argument( | |
"--private-key-file", | |
default="private_key.json", | |
help="Private key file", | |
) | |
parser.add_argument( | |
"--nonce", | |
type=int, | |
default=0, | |
help="nonce", | |
) | |
parser.add_argument( | |
"--count", | |
type=int, | |
default=10000, | |
help="count", | |
) | |
args = parser.parse_args() | |
w3 = Web3(HTTPProvider(args.provider)) | |
with open(args.private_key_file) as keyfile: | |
encrypted_key = keyfile.read() | |
private_key = w3.eth.account.decrypt(encrypted_key, "") | |
acct = w3.eth.account.from_key(private_key) | |
if args.nonce == 0: | |
nonce = w3.eth.get_transaction_count(acct.address) | |
else: | |
nonce = args.nonce | |
chain_id = w3.eth.chain_id | |
for n in range(0, args.count): | |
txn = dict( | |
nonce=nonce + n, | |
gasPrice=0, | |
gas=10240000, | |
to=acct.address, | |
value=0, | |
data=b"1" * 102400, | |
) | |
signed_txn = w3.eth.account.sign_transaction(txn, private_key) | |
txhash = w3.eth.send_raw_transaction(signed_txn.rawTransaction) | |
logging.info(f"{txn} -> {txhash.hex()}") | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
then check the txpool status, you'll see something like this: