1. ETHS銘文
ETHS銘文是以太坊銘文協(xié)議Ethscriptions的代幣名稱(chēng)。Ethscriptions是一個(gè)基于以太坊的銘文協(xié)議,允許用戶(hù)在以太坊主網(wǎng)上刻入不同類(lèi)型的文件,并將其記錄到區(qū)塊中。ETHS作為Ethscriptions的第一個(gè)"概念幣",引起了人們的關(guān)注和熱議。
以太坊銘文協(xié)議Ethscriptions的特點(diǎn)包括:
- 使用交易調(diào)用數(shù)據(jù)在以太坊上創(chuàng)建和共享數(shù)字藏品的新協(xié)議[1]。
- 利用以太坊calldata進(jìn)行銘文創(chuàng)作,相比使用合約儲(chǔ)存更便宜、去中心化,并且能夠保證所有有效內(nèi)容的全球唯一性。
- 銘文的大小不能超過(guò)96KB。
ETHS銘文的鑄造方式相對(duì)簡(jiǎn)單,以下是一個(gè)示例的鑄造步驟:
- 復(fù)制代碼:data:,{“p”:“erc-20”,“op”:“mint”,“tick”:“eths”,“id”:“21000以?xún)?nèi)的任意數(shù)字”,“amt”:“1000”}。
- 將這串代碼進(jìn)行轉(zhuǎn)碼,轉(zhuǎn)為16進(jìn)制。
- 打開(kāi)錢(qián)包,向自己的地址轉(zhuǎn)入0ETH,并將轉(zhuǎn)碼獲得的16進(jìn)制填寫(xiě)。
- 確認(rèn)付款,完成代幣的鑄造。
需要注意的是,ETHS銘文的共識(shí)承認(rèn)只限于編號(hào)在21000以?xún)?nèi)的銘文,而且對(duì)于重復(fù)被打的編號(hào),只有最先被打的那張ETHS銘文會(huì)被承認(rèn)。
2.批量查詢(xún)是否被mint
首先安裝包:
pip install requests
import hashlib
import json
import requests
import threading
def query_content(content):
content1 = "data:," + content
sha256_hash = hashlib.sha256(content1.encode()).hexdigest()
url = f"https://eth-script-indexer-eca25c4cf43b.herokuapp.com/api/ethscriptions/exists/{sha256_hash}"
try:
response = requests.get(url)
if response.status_code == 200:
result = response.json()
if result['result']:
# owner = result['ethscription']['current_owner']
# creator = result['ethscription']['creator']
# creation_timestamp = result['ethscription']['creation_timestamp']
#
# # 轉(zhuǎn)換時(shí)間格式為易讀形式
# creation_timestamp = datetime.datetime.strptime(
# creation_timestamp, "%Y-%m-%dT%H:%M:%S.%fZ")
#
return -1
else:
# hex_content = binascii.hexlify(content.encode()).decode()
# print(f"\n'{content}'的銘文內(nèi)容尚未被銘刻。")
# print(f"該銘文文本(含data:,)的16進(jìn)制輸出為:{hex_content}")
return json.loads(content)["id"]
else:
print(f"\n獲取'{content}'的數(shù)據(jù)失敗,請(qǐng)檢查你的輸入是否正確。")
except requests.exceptions.RequestException as e:
print(f"\n發(fā)送請(qǐng)求時(shí)遇到錯(cuò)誤: {e}")
def main(name, id_min, id_max):
ids = []
lock = threading.Lock()
def process_content(name, id):
content = '{"p":"erc-20","op":"mint","tick":"' + name + '","id":"' + str(number) + '","amt":"1000"}'
id = query_content(content)
with lock:
ids.append(id)
# 創(chuàng)建線程列表
threads = []
for number in range(id_min, id_max):
thread = threading.Thread(target=process_content, args=(name, number,))
threads.append(thread)
thread.start()
# 限制線程數(shù)量為20
if len(threads) >= 20:
# 等待前面的線程完成
for t in threads:
t.join()
threads = []
# 等待剩余線程完成
for thread in threads:
thread.join()
# 過(guò)濾掉值為-1的元素
ids = list(filter(lambda x: x != -1, ids))
print("未打銘文列表:",ids)
if __name__ == '__main__':
id_min = int(input("請(qǐng)輸入查詢(xún)id范圍下限:"))
id_max = int(input("請(qǐng)輸入查詢(xún)id范圍上限:"))
name = input("輸入銘文名稱(chēng):")
main(name, id_min, id_max)
3. 批量mint
安裝web3包
pip install web3 eth_account
import hashlib
import threading
import time
from web3 import Web3, HTTPProvider
from eth_account import Account
import concurrent.futures
import requests
from eth_account.signers.local import LocalAccount
import binascii
def string_to_hex(string):
return '0x' + binascii.hexlify(string.encode()).decode()
def query_domain(content):
content_ = "data:," + content
sha256_hash = hashlib.sha256(content_.encode()).hexdigest()
url = f"https://eth-script-indexer-eca25c4cf43b.herokuapp.com/api/ethscriptions/exists/{sha256_hash}"
try:
response = requests.get(url)
if response.status_code == 200:
result = response.json()
if result['result']:
print(content, "不能被mint")
return False
else:
print(content, "可以mint")
return True
else:
print(f"\n獲取'{content}'的數(shù)據(jù)失敗,請(qǐng)檢查你的輸入是否正確。")
except requests.exceptions.RequestException as e:
print(f"\n發(fā)送請(qǐng)求時(shí)遇到錯(cuò)誤: {e}")
def mint_ethscriptions(w3, wallet, to_address, private_key, content):
nonce = w3.eth.get_transaction_count(wallet.address)
# 獲取當(dāng)前燃?xì)鈨r(jià)格
gas_price = w3.eth.gas_price
hex_data_URI = string_to_hex("data:," + content)
tx = {
'to': to_address,
'value': w3.to_wei(0, 'ether'), # 發(fā)送的以太幣數(shù)量
'data': hex_data_URI,
'nonce': nonce,
'gas': 30000, # 估算的燃?xì)饬?/span>
'gasPrice': gas_price,
'chainId': 1, # 主網(wǎng)的鏈ID
}
# 使用私鑰進(jìn)行交易簽名
# signed_transaction = w3.eth.account.sign_transaction(tx, private_key)
# tx_hash = w3.eth.send_raw_transaction(signed_transaction.rawTransaction)
# print(f'Transaction hash: {tx_hash.hex()}')
#
# tx_receipt = w3.eth.wait_for_transaction_receipt(tx_hash)
# print(f'Transaction was confirmed in block {tx_receipt["blockNumber"]}')
print('Done')
def main(private_key, name, id_min, id_max):
w3 = Web3(HTTPProvider("https://rpc.ankr.com/eth"))
wallet: LocalAccount = Account.from_key(private_key)
count = 0 # 計(jì)數(shù)器
count_lock = threading.Lock() # 創(chuàng)建鎖對(duì)象
def process_id(name, number):
global count
content = '{"p":"erc-20","op":"mint","tick":"' + name + '","id":"' + str(number) + '","amt":"1000"}'
flag = query_domain(content)
if flag:
with count_lock:
if count < 100:
mint_ethscriptions(w3, wallet, wallet.address, private_key, content)
count += 1
with concurrent.futures.ThreadPoolExecutor() as executor:
ids = range(id_min, id_max)
names = [name] * len(ids)
for i in range(0, len(ids), 20):
batch_ids = ids[i:i + 20]
batch_names = names[i:i + 20]
executor.map(process_id, batch_names, batch_ids)
time.sleep(10) # 休息60秒
if __name__ == '__main__':
private_key = input("請(qǐng)輸入錢(qián)包私鑰:")
name = input("請(qǐng)輸入要mint的銘文名字:")
id_min = int(input("請(qǐng)輸入銘文編號(hào)下限:"))
id_max = int(input("請(qǐng)輸入銘文編號(hào)上限:"))
main(private_key, name, id_min, id_max)
文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-760114.html
有問(wèn)題歡迎私聊,可+量化交易~裙,領(lǐng)取量化交易資料文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-760114.html
到了這里,關(guān)于【Mquant】9:python批量銘刻erc-20銘文的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!