update eth
This commit is contained in:
parent
e8e7c59579
commit
1c18726066
@ -4,7 +4,8 @@ import json
|
|||||||
rpc_url = "https://ethereum-holesky-rpc.publicnode.com"
|
rpc_url = "https://ethereum-holesky-rpc.publicnode.com"
|
||||||
chain = Web3(Web3.HTTPProvider(rpc_url))
|
chain = Web3(Web3.HTTPProvider(rpc_url))
|
||||||
contract_address = "0x642C23F91bf8339044A00251BC09d1D98110C433"
|
contract_address = "0x642C23F91bf8339044A00251BC09d1D98110C433"
|
||||||
contract_abi = json.loads('''[
|
contract_abi = json.loads(
|
||||||
|
"""[
|
||||||
{
|
{
|
||||||
"anonymous": false,
|
"anonymous": false,
|
||||||
"inputs": [
|
"inputs": [
|
||||||
@ -37,23 +38,26 @@ contract_abi = json.loads('''[
|
|||||||
"stateMutability": "nonpayable",
|
"stateMutability": "nonpayable",
|
||||||
"type": "function"
|
"type": "function"
|
||||||
}
|
}
|
||||||
]''')
|
]"""
|
||||||
|
)
|
||||||
contract = chain.eth.contract(address=contract_address, abi=contract_abi)
|
contract = chain.eth.contract(address=contract_address, abi=contract_abi)
|
||||||
wallet_address = "0xe02666Cb63b3645E7B03C9082a24c4c1D7C9EFf6"
|
wallet_address = "0xe02666Cb63b3645E7B03C9082a24c4c1D7C9EFf6"
|
||||||
pk = "ae66ae3711a69079efd3d3e9b55f599ce7514eb29dfe4f9551404d3f361438c6"
|
pk = "ae66ae3711a69079efd3d3e9b55f599ce7514eb29dfe4f9551404d3f361438c6"
|
||||||
|
|
||||||
|
|
||||||
def call_eth_logger(wallet_address, pk, message: str):
|
def call_eth_logger(wallet_address, pk, message: str):
|
||||||
transaction = contract.functions.logmessage(message).build_transaction({
|
transaction = contract.functions.logmessage(message).build_transaction(
|
||||||
'chainId': 17000,
|
{
|
||||||
'gas': 30000,
|
"chainId": 17000,
|
||||||
'gasPrice': chain.to_wei('10', 'gwei'),
|
"gas": 30000,
|
||||||
'nonce': chain.eth.get_transaction_count(wallet_address, 'pending'),
|
"gasPrice": chain.to_wei("10", "gwei"),
|
||||||
})
|
"nonce": chain.eth.get_transaction_count(wallet_address, "pending"),
|
||||||
|
}
|
||||||
|
)
|
||||||
signed_tx = chain.eth.account.sign_transaction(transaction, private_key=pk)
|
signed_tx = chain.eth.account.sign_transaction(transaction, private_key=pk)
|
||||||
tx_hash = chain.eth.send_raw_transaction(signed_tx.raw_transaction)
|
tx_hash = chain.eth.send_raw_transaction(signed_tx.raw_transaction)
|
||||||
print(tx_hash)
|
print(tx_hash)
|
||||||
receipt = chain.eth.wait_for_transaction_receipt(tx_hash)
|
receipt = chain.eth.wait_for_transaction_receipt(tx_hash)
|
||||||
transfer_event = contract.events.messageLog().process_receipt(receipt)
|
transfer_event = contract.events.messageLog().process_receipt(receipt)
|
||||||
for event in transfer_event:
|
for event in transfer_event:
|
||||||
print(event['args']['msg'])
|
print(event["args"]["msg"])
|
||||||
|
8
src/eth_logger_test.py
Normal file
8
src/eth_logger_test.py
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
from eth_logger import call_eth_logger
|
||||||
|
|
||||||
|
wallet_address = (
|
||||||
|
"0xe02666Cb63b3645E7B03C9082a24c4c1D7C9EFf6" # 修改成要使用的钱包地址/私钥
|
||||||
|
)
|
||||||
|
wallet_pk = "ae66ae3711a69079efd3d3e9b55f599ce7514eb29dfe4f9551404d3f361438c6"
|
||||||
|
|
||||||
|
call_eth_logger(wallet_address, wallet_pk, "hello World")
|
10
src/logger.sol
Normal file
10
src/logger.sol
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
pragma solidity ^0.8.0;
|
||||||
|
|
||||||
|
contract logger{
|
||||||
|
event messageLog(string msg);
|
||||||
|
function logmessage(string memory text) public returns (bool){
|
||||||
|
emit messageLog(text);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -186,7 +186,7 @@ wallet_pk = "ae66ae3711a69079efd3d3e9b55f599ce7514eb29dfe4f9551404d3f361438c6"
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
import uvicorn # pylint: disable=e0401
|
import uvicorn
|
||||||
|
|
||||||
threading.Thread(target=log_message).start()
|
threading.Thread(target=log_message).start()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user