defmint_tokens(account,token_address,amount,attempts=18): rng_functions = json.load(open('./data/rng.json'))if token_address notin rng_functions:raiseException("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 inlist(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)exceptExceptionas e:if error :=interpret_exception_message(e): logging.error("{} to mint {}".format(error, rng_functions[token_address]['label']))returnFalseelse: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']))returnFalsereturnTrue
Description
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