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 True