Web3.py를 이용한 특정컨트랙트 이벤트로그 가져오기

from web3 import Web3
import json

w3 = Web3(Web3.HTTPProvider(‘https://public-node-api.klaytnapi.com/v1/cypress’))

abi = [
{
“anonymous”: False,
“inputs”: [
{
“indexed”: False,
“name”: “tokenA”,
“type”: “address”
},
{
“indexed”: False,
“name”: “amountA”,
“type”: “uint256”
},
{
“indexed”: False,
“name”: “tokenB”,
“type”: “address”
},
{
“indexed”: False,
“name”: “amountB”,
“type”: “uint256”
}
],
“name”: “ExchangePos”,
“type”: “event”
}

]

abi_str = json.dumps(abi)
address = Web3.toChecksumAddress(‘0xc6a2ad8cc6e4a7e08fc37cc5954be07d499e7654’)
my_contract = w3.eth.contract(address=address, abi=abi_str)
result = my_contract.events.ExchangePos().createFilter(fromBlock=‘latest’)
event_list=result.get_all_entries()
print(event_list)

web3 py를 이용하여 간단하게 해당컨트랙트의 ExchangePos의 이벤트를 최근블럭것을 받아올수있나 확인해보았는데요.

결과값은 ' ’ 을 나타내고
지속 시도하면
“ValueError: The provided value did not satisfy any of the formatter conditions”
발생합니다.

해당 코드를 이런식으로 변경하면
abi_str = json.dumps(abi)
address = Web3.toChecksumAddress(‘0xc6a2ad8cc6e4a7e08fc37cc5954be07d499e7654’)
my_contract = w3.eth.contract(address=address, abi=abi_str)
result = my_contract.events.ExchangePos().createFilter(fromBlock=‘latest’)
logs = w3.eth.get_logs({“filter_id”: result.filter_id})
for log in logs:
print(log)

결과값은


이런식으로 HexBytes로 나오고 단 하나의 블럭만 나옵니다

해당 ABI input값으로 나오지 않는 이유가 뭔가요?

혹시 이유를 아시는분이 계시다면 답변부탁드립니다.
이제 막 살펴본 초짜라 자세히 모릅니다 ㅜ

안녕하세요, 발생하는 에러를 그대로 올려주시면 좋을것같습니다.

그리고 마지막 스크린샷에 나온 get_logs의 결과값은 get_logs 를 참고하시면 됩니다.

1개의 좋아요

get_logs로 잘뽑아냈습니다!
:+1:

1개의 좋아요