Last active
June 13, 2023 14:59
-
-
Save knoman8128/5eea312b9ee5170294f486b914ba99b7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
from web3 import Web3 | |
from getpass import getpass | |
from eth_hash.auto import keccak | |
from eth_account import Account | |
def b2i(bstr): | |
num = 0 | |
for index in range(len(bstr)): | |
num += int(bstr[index]) * (16 ** (index * 2) + 1) | |
return num | |
def keygen(nonce, key, uai): | |
packed = uai.to_bytes(32, 'big') + key.to_bytes(32, 'big') + nonce.to_bytes(32, 'big') | |
hashed = keccak(packed) | |
return b2i(hashed) | |
def keymod(nonce, randomKey, addr, basicRate): | |
result = keygen(nonce, randomKey, addr) | |
return result % basicRate | |
def load_wallet_from_json(json_file_path, password): | |
with open(json_file_path, 'r') as file: | |
encrypted_json = file.read() | |
private_key = w3.eth.account.decrypt(encrypted_json, password) | |
return Account.from_key(private_key) | |
contracts = { | |
"GEMT9": ["0x9F57B97a6723b1620A6360af33B28d006806EC0d", 13, 20], | |
"NEMT9": ["0x2e23950C00bDd2505EE64494bc554e59050C70Ce", 13, 18], | |
} | |
if len(sys.argv) < 3: | |
print("ex: python mine.py gemt9 wallet.json") | |
quit() | |
contractName = (sys.argv[1]).upper() | |
if contractName not in contracts: | |
print("token name: gemt9 or nemt9") | |
quit() | |
wallet = sys.argv[2] | |
if not os.path.isfile(wallet): | |
print(wallet, "not found") | |
quit() | |
w3 = Web3(Web3.HTTPProvider("https://bsc-dataseed1.ninicoin.io")) | |
password = getpass("Enter wallet password: ") | |
if password == "q" or password == "": | |
quit() | |
try: | |
account = load_wallet_from_json(wallet, password) | |
except ValueError: | |
print("password mismatched") | |
quit() | |
address = account.address | |
basicRate = int(w3.eth.get_storage_at( | |
contracts[contractName][0], contracts[contractName][1]).hex(), 0) | |
randomKey = int(w3.eth.get_storage_at( | |
contracts[contractName][0], contracts[contractName][2]).hex(), 0) | |
iter = 100000 | |
modulus = randomKey % basicRate | |
for nonce in range(iter): | |
if keymod(nonce, randomKey, int(address, 0), basicRate) == modulus: | |
break | |
if nonce+1 >= iter: | |
print("couldn't find nonce, pls increase iter") | |
quit() | |
data = int("0x4d4748980000000000000000000000000000000000000000000000000000000000000000", 0) + nonce | |
print(contractName, contracts[contractName][0]) | |
print(basicRate, randomKey) | |
print("nonce", nonce, hex(nonce)) | |
print("data", hex(data)) | |
cont = input("Send mine tx? (y/n): ") | |
if cont.upper() != "Y": | |
quit() | |
tx_nonce = w3.eth.get_transaction_count(account.address) | |
raw_transaction = { | |
'nonce': tx_nonce, | |
'to': contracts[contractName][0], | |
'value': 0, | |
'gas': 200000, | |
'gasPrice': w3.eth.gas_price, | |
'data': data, | |
} | |
signed_transaction = w3.eth.account.sign_transaction(raw_transaction, private_key=account.key) | |
tx_hash = w3.eth.send_raw_transaction(signed_transaction.rawTransaction) | |
print("https://bscscan.com/tx/" + tx_hash.hex()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment