1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
| from web3 import Web3
abi = """[{"inputs":[],"name":"test6","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"test7","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"test8","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"msg","type":"string"}],"name":"testError","type":"error"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"test1","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"test2","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"test3","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"test4","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"test5","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}]"""
w3 = Web3(Web3.HTTPProvider("https://bsc.getblock.io/testnet/?api_key=5deb2510-62f9-40a9-b0e0-0039f9025ded"))
address = "0xD1B260aba3bA6f3D3099725b1b1C7cdD12581974" contract = "0xf9E70F3d6dcC64D25f557e06becC6760bF0245D2" private = ""
contract_ = w3.eth.contract( address=Web3.toChecksumAddress(contract), abi=abi)
def encode_test6(): tx_dic = contract_.functions.test6(). \ buildTransaction( { 'gas': 500000, } ) return tx_dic
def encode_test7(): tx_dic = contract_.functions.test7(). \ buildTransaction( { 'gas': 500000, } ) return tx_dic
def encode_test8(): tx_dic = contract_.functions.test8(). \ buildTransaction( { 'gas': 500000, } ) return tx_dic
def send_transaction(tx_dic): nonce = w3.eth.getTransactionCount(address) tx_dic["nonce"] = nonce tx_dic['gasPrice'] = w3.eth.gasPrice sign_tx = w3.eth.account.signTransaction(tx_dic, private_key=private) txn_hash = w3.eth.sendRawTransaction(sign_tx.rawTransaction) return Web3.toHex(txn_hash)
def get_wait_receipt(tx): data = w3.eth.waitForTransactionReceipt(tx) return data
if __name__ == '__main__': tx_dic = encode_test6() tx = send_transaction(tx_dic) data = get_wait_receipt(tx) print(data) tx_dic = encode_test7() tx = send_transaction(tx_dic) data = get_wait_receipt(tx) print(data) tx_dic = encode_test8() tx = send_transaction(tx_dic) data = get_wait_receipt(tx) print(data)
|