Untitled
unknown
plain_text
2 years ago
2.4 kB
32
Indexable
from web3 import Web3, Account
from eth_account.messages import encode_defunct
import os
import requests
from fake_useragent import UserAgent
from dotenv import load_dotenv
load_dotenv()
w3 = Web3(Web3.HTTPProvider('https://rpc.ankr.com/bsc'))
keys = os.getenv("key").split(',') #key = 0x,0x,0x
class Dapp:
def __init__(self, key) -> None:
self.session = requests.session()
self.gaslimt = 1000000
self.ac = Account.from_key(key)
self.headers = {"user-agent": UserAgent().random}
self.signature = ""
self.accessToken = ""
def signMsg(self):
msg = "AI + DYOR = Ultimate Answer to Unlock Web3 Universe"
self.signature = self.ac.sign_message(encode_defunct(text= msg))['signature'].hex()
def login(self):
url = "https://api.qna3.ai/api/v2/auth/login?via=wallet"
payload = {
"wallet_address": self.ac.address,
"signature": self.signature
}
response = self.session.post(url= url, headers= self.headers, data= payload, timeout= 60)
self.accessToken = response.json()['data']['accessToken']
def checkIn(self):
transaction = {
'to': '0xB342e7D33b806544609370271A8D074313B7bc30',
'data': '0xe95a644f0000000000000000000000000000000000000000000000000000000000000001',
'nonce': w3.eth.get_transaction_count(self.ac.address),
'value': 0,
'chainId': 56,
'gas': self.gaslimt,
'gasPrice': w3.eth.gas_price
}
signed = self.ac.sign_transaction(transaction)
tx = w3.eth.send_raw_transaction(signed.rawTransaction)
print(f"https://bscscan.com/tx/{tx.hex()}")
payload = {
"hash": tx.hex(),
"via": "bnb"
}
self.headers["Authorization"] = "Bearer " + self.accessToken
url = "https://api.qna3.ai/api/v2/my/check-in"
response = self.session.post(url= url, headers= self.headers, json= payload, timeout= 60)
return response
def run(self):
try:
dapp.signMsg()
dapp.login()
self.checkIn()
except Exception as e:
print(f"登录: {e}")
if __name__ == "__main__":
for key in keys:
dapp = Dapp(key= key)
dapp.run()
Editor is loading...
Leave a Comment