How to airdrop crypto to multiple accounts using Python

An airdrop is a marketing method that involves sending crypto tokens to many accounts programmatically in order to promote awareness of a crypto currency. Airdrops are usually small amounts of crypto currency sent to addresses of active members of the blockchain community for free or in return for a service.

Qualifications for an airdrop are usually custom to the project giving away the crypto tokens. Recipients may need to hold a minimum quantity of the crypto tokens in their account or interact with a service or they may need to perform a certain task such as blogging, creating a video, posting on social media, etc.

How to airdrop crypto to multiple accounts using Python

Advantages of airdrops

An airdrop is an attempt to stand out from all the other tokens that exist. A crypto currency is worthless if it is not used and adopted by a community to encourage widespread usage.

Disadvantages of airdrops

Crypto airdrops are usually for crap coins that can end up being pump-and-dump scams. Be smart and watch out for scammers. No one gives away something that is truly valuable for free.

Python code to airdrop crypto tokens

The Python code below is a simple script that allows you to send the same amount of Ether to many accounts. To use this program you need:

  • Pip install web3. This library will allow Python to interact with the Ethereum blockchain
  • Connect to an end point. You can use Infura or any other node that is running Ethereum
  • Have an Ethereum account and private key
  • Create your own ERC20 token. If you do not have a token to airdrop read this tutorial to learn how to create your own ERC20 token on Ethereum
  • Keep in mind you need to pay gas fees for sending tokens to accounts

The program below:

  • Supports a comma separated list of Ethereum addresses
  • Processes these addresses through a loop
  • Creates a transaction for each address to send the same amount of ETH

from web3 import Web3
import time

# enter your private key.  Be careful with your private key
private_key = "YOURPRIVATEKEY"

# add your blockchain connection information
infura_url = 'ADDYOURINFURAKEY'
web3 = Web3(Web3.HTTPProvider(infura_url))
print(web3.isConnected())

# enter the account that the crypto is being sent from
from_account ="ENTERYOURACCOUNT"

# enter a list of accounts that the crypto is being sent to
to_addresses = ("account1", "account2", "account2")

# get from account balance so you can monitor
sending_account_balance = web3.eth.get_balance(from_account)
balance = web3.fromWei(sending_account_balance, "ether")
print(balance)

# loop through each of the to_addresses and send Ether in the amount designated below
for i in to_addresses:
    print(i)

    nonce = web3.eth.getTransactionCount(from_account)

    tx = {
        'nonce': nonce,
        'to': web3.toChecksumAddress(i),
        'value': web3.toWei(.005, 'ether'),
        'gas': 21000,
        'gasPrice': web3.toWei('50', 'gwei')
    }

# sign the transaction and print on the screen
# wait 5 seconds before processing the next transaction
    signed_tx = web3.eth.account.sign_transaction(tx, private_key)
    tx_hash = web3.eth.sendRawTransaction(signed_tx.rawTransaction)
    transaction = web3.toHex(tx_hash)
    print(transaction)
    time.sleep(5)

Modify the script above by implementing the following enhancements:

  • Read the list of accounts from a text file
  • Build a targeted list accounts or use The Graph QL to query the blockchain for a list of accounts that meet a specific condition.
  • Send your token to each account based on the users balance
  • Modify the script to send your own custom token (ERC20 or ERC721)

This code is for learning and entertainment purposes only. The code has not been audited and use at your own risk. Remember smart contracts are experimental and could contain bugs.

Next – Use The Graph in Python to query Ethereum data

Ledger Nano X - The secure hardware wallet

1 thought on “How to airdrop crypto to multiple accounts using Python

Leave a Reply