| 12
 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
 
 | from web3 import Web3
 abi = """
 [{"constant":false,"inputs":[{"name":"x","type":"uint256"}],"name":"set","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"get","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"}]
 """
 
 w3 = Web3(Web3.HTTPProvider("https://ropsten.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161"))
 contractObj = w3.eth.contract(
 address=Web3.toChecksumAddress("0xB5B990E8B01f00d2C319D427b395d00435d910d5"), abi=abi)
 
 print(contractObj.functions.get().call())
 
 dex_address = ""
 dex_private = ""
 
 
 def set_number_5():
 tx_dic = contractObj.functions.set(
 5
 ). \
 buildTransaction(
 {
 'gas': 500000,
 }
 )
 
 nonce = w3.eth.getTransactionCount(dex_address)
 tx_dic["nonce"] = nonce
 tx_dic['gasPrice'] = w3.eth.gasPrice
 sign_tx = w3.eth.account.signTransaction(tx_dic, private_key=dex_private)
 txn_hash = w3.eth.sendRawTransaction(sign_tx.rawTransaction)
 print(Web3.toHex(txn_hash))
 
 
 def set_number_10():
 tx_dic = contractObj.functions.set(
 10
 ). \
 buildTransaction(
 {
 'gas': 500000,
 }
 )
 
 nonce = w3.eth.getTransactionCount(dex_address)
 tx_dic["nonce"] = nonce
 tx_dic['gasPrice'] = w3.eth.gasPrice
 sign_tx = w3.eth.account.signTransaction(tx_dic, private_key=dex_private)
 txn_hash = w3.eth.sendRawTransaction(sign_tx.rawTransaction)
 print(Web3.toHex(txn_hash))
 
 if __name__ == '__main__':
 set_number_10()
 
 |