# $AVAL铭文批量脚本 **Published by:** [Y](https://paragraph.com/@444526/) **Published on:** 2023-11-22 **URL:** https://paragraph.com/@444526/aval ## Content 1、安装python运行环境 https://www.python.org/ 安装完成后自行百度配置本地环境 运行你的脚本文件即可 2、代码import time from eth_account import Account from eth_account.signers.local import LocalAccount from web3 import Web3 w3 = Web3(Web3.HTTPProvider("https://rpc.ankr.com/avalanche")) private_key = input("你的私钥:") mint_num = int(input("铸造的数量:")) account: LocalAccount = Account.from_key(private_key) start_nonce = w3.eth.get_transaction_count(account.address) nonce = start_nonce def estimate_gas(txn): gas = w3.eth.estimate_gas({ "from": txn['from'], "to": txn['to'], "value": txn['value'], "data": txn['data'] }) gas = int(gas + (gas / 10)) # increase 10% of the gas return gas def Mint(private_key): global account global start_nonce global nonce transaction = { "from": account.address, "nonce": nonce, "value": 0, "gas": 33036, "gasPrice": int(w3.eth.gas_price * 1.1), "to": account.address, # "chainId": 43114, # Updated chainId to Avalanche Fuji C-Chain 暂时不需要链id "data": "0x646174613a2c7b2270223a226173632d3230222c226f70223a226d696e74222c227469636b223a226176616c222c22616d74223a22313030303030303030227d" } transaction.update({'gas': int(estimate_gas(transaction))}) signer = account.sign_transaction(transaction_dict=transaction) tx = w3.eth.send_raw_transaction(signer.rawTransaction) tx_hash = Web3.to_hex(tx) # 检查交易状态 while True: try: result = w3.eth.get_transaction_receipt(transaction_hash=tx_hash) if result is None or result['blockNumber'] is None: time.sleep(3) elif result['status']: print(f"[成功] - https://cchain.explorer.avax.network/tx/{tx_hash}") nonce += 1 return result['contractAddress'] else: print(f"[失败] - https://cchain.explorer.avax.network/tx/{tx_hash}") return False except: time.sleep(2) if __name__ == '__main__': try: for i in range(mint_num): print("当前铸造的数量:", i + 1) Mint(private_key) print("铸造完成...") time.sleep(2) except Exception as e: print("报错信息如下:") print(e) sys.exit(0) print("程序执行完毕自动退出") 3、如何铸造别的链的铭文 在chainlist中找对应的rpc节点修改 https://chainlist.org/ (1)、修改rpc节点w3 = Web3(Web3.HTTPProvider("https://rpc.ankr.com/avalanche")) (2)、修改data的16进制数据 修改其中data的数据改为需要铸造的16进制即可 transaction = { "from": account.address, "nonce": nonce, "value": 0, "gas": 33036, "gasPrice": int(w3.eth.gas_price * 1.1), "to": account.address, # "chainId": 43114, # Updated chainId to Avalanche Fuji C-Chain 暂时不需要链id "data": "0x646174613a2c7b2270223a226173632d3230222c226f70223a226d696e74222c227469636b223a226176616c222c22616d74223a22313030303030303030227d" } (3)修改链上rpc 将其中的血崩链接改成自己的链信息即可 if result is None or result['blockNumber'] is None: time.sleep(3) elif result['status']: print(f"[成功] - https://cchain.explorer.avax.network/tx/{tx_hash}") nonce += 1 return result['contractAddress'] else: print(f"[失败] - https://cchain.explorer.avax.network/tx/{tx_hash}") return False ## Publication Information - [Y](https://paragraph.com/@444526/): Publication homepage - [All Posts](https://paragraph.com/@444526/): More posts from this publication - [RSS Feed](https://api.paragraph.com/blogs/rss/@444526): Subscribe to updates