mint_tokens
Function
def mint_tokens(account, token_address, amount, attempts=18):
rng_functions = json.load(open('./data/rng.json'))
if token_address not in rng_functions:
raise Exception("Mint/RNG function not available for {}".format(token_address))
call_function = random.choice(list(rng_functions[token_address]['functions']))
token_contract = load_contract(token_address, load_contract_abi(token_address))
token_info = get_token_info(token_address)
loops = math.ceil(amount / rng_functions[token_address]['mints'])
for i in list(range(0, loops)):
tx = getattr(token_contract.functions, call_function)().build_transaction({
"from": account.address,
"nonce": get_nonce(account.address)
})
try:
success = broadcast_transaction(account, tx, False, attempts)
except Exception as e:
if error := interpret_exception_message(e):
logging.error("{} to mint {}".format(error, rng_functions[token_address]['label']))
return False
else:
if success:
logging.info("Called mint function for {} ({})".format(token_info['name'], token_info['symbol']))
else:
logging.warning(
"Failed to call mint function for {} ({})".format(token_info['name'], token_info['symbol']))
return False
return TrueDescription
Load a list of RNG functions
Check if the desired token has a mint function
Get a random mint function to call for the token contract
Load the contract for the desired token
Get the info for the desired token
Determine how many loops are needed to mint enough tokens
Loop enough times to satisfy the amount
Create a transaction and call the mint function
Broadcast and start again
Return True/False
\