트랜잭션 실행 후 Receipt 데이터 분석

안녕하세요, 클린이입니다.
kaikas로 함수를 실행하고 나온 receipt 를 분석해서 어떤 일들이 일어났는지 보려고 하는데,
docs에는
caver.abi.decodeLog(inputs, hexstring, topics)
이던데 inputs이랑 hexstring에 receipt의 어떤 값을 넣어야 하는지 정확히 잘 모르겠네요
일단 여러가지 조합으로 넣어보다가 아래처럼 넣어보니 값이 나오긴 하는데,
주소도 아닌 것이… 이상하게 나와서요.

또 이더쪽 글들을 보면 hexstring에 receipt.logs[0].data 를 넣으라고 하던데…
카이카스의 receipt는 Data항목이 ‘0x’ 로 오고 있어서 이게 맞는건지도 문의 드립니다.


this.caver.klay.abi.decodeLog([{
		"name": "to",
		"type": "address"
	}],
	'0x1424438500000000000000000000000066a81d2333c6488d1e6608542f4dae413609b7e5',
	['0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef', 
	'0x000000000000000000000000174a142cf4cfb6947cf4651c9eb8f8001137905b',
	'0x00000000000000000000000066a81d2333c6488d1e6608542f4dae413609b7e5',
	'0x000000000000000000000000000000000000000000000000000000000000000a'
])
//0: "0x0000000066A81D2333C6488D1e6608542F4daE41"
//to: "0x0000000066A81D2333C6488D1e6608542F4daE41"

//받은 receipt
blockHash: "0xc1d69901ff684f01f4d79111570a4650331640b5d227db3ea7d89fc9f9c81f44"
blockNumber: 77832096
contractAddress: null
from: "0x66a81d2333c6488d1e6608542f4dae413609b7e5"
gas: "0x7a1200"
gasPrice: "0x5d21dba00"
gasUsed: 89272
input: "0x1424438500000000000000000000000066a81d2333c6488d1e6608542f4dae413609b7e5"
logs: Array(1)
0:
address: "0xb7Efa422c91bD1b01b117f9F415883DE32921727"
blockHash: "0xc1d69901ff684f01f4d79111570a4650331640b5d227db3ea7d89fc9f9c81f44"
blockNumber: 77832096
data: "0x"
id: "log_2ca4cee4"
logIndex: 0
topics: Array(4)
0: "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"
1: "0x000000000000000000000000174a142cf4cfb6947cf4651c9eb8f8001137905b"
2: "0x00000000000000000000000066a81d2333c6488d1e6608542f4dae413609b7e5"
3: "0x000000000000000000000000000000000000000000000000000000000000000a"
length: 4
[[Prototype]]: Array(0)
transactionHash: "0xdddc1110702d24a081675d91f1922cb5d821065c6751001c8f753b6099a4a93b"
transactionIndex: 0
[[Prototype]]: Object
length: 1
[[Prototype]]: Array(0)
logsBloom: "0x00000000000000000000000004000000000000000000000000000000000000000000000000000080000000000000000000000000040000000020000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010200000000000000000001000010000000000000000000000000000100000000000000000000000000000000000000000000000000000400000000000000000000000000000000002008000000000000000000000000000000000000000000000001000000000000000000000100000000000000000000000000000000000000000000000"
nonce: "0xf"
senderTxHash: "0xdddc1110702d24a081675d91f1922cb5d821065c6751001c8f753b6099a4a93b"
signatures: Array(1)
0:
R: "0x8ba0639d48effaf05ed0f5435b0982e6fee2a5c23bfb2fe9de278ef561b97fe"
S: "0x627308d43406b38007fafb6f65bac6238c3c5827a6759ec82fb45d229989ca1b"
V: "0x7f6"
[[Prototype]]: Object
length: 1
[[Prototype]]: Array(0)
status: true
to: "0xb7efa422c91bd1b01b117f9f415883de32921727"
transactionHash: "0xdddc1110702d24a081675d91f1922cb5d821065c6751001c8f753b6099a4a93b"
transactionIndex: 0
type: "TxTypeSmartContractExecution"
typeInt: 48
value: "0x16345785d8a0000"

안녕하세요, 저 로그가 어떤 이벤트로 인해서 기록된 것인지 알 수 없어서 data에 값이 valid한지 말씀드리기가 어렵습니다.

아래는 decodeLog를 사용하는 예시입니다. 참고 부탁드립니다.

// logs 예시
[
  {
    address: '0xf0C398035a88c0dFFE23A71bC991a247A24Da4D5',
    topics: [
      '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
      '0x00000000000000000000000060498fefbf1705a3db8d7bb5c80d5238956343e5',
      '0x00000000000000000000000060498fefbf1705a3db8d7bb5c80d5238956343e5'
    ],
    data: '0x00000000000000000000000000000000000000000000000000000000000003e8',
    blockNumber: 78041908,
    transactionHash: '0x11020e757583dafa31c39b0e1d43a9b9cb52d83d073bca2a844ae13f9088a86b',
    transactionIndex: 0,
    blockHash: '0xda0dd92cf04e230755ecc41b9de1c86c5d1eb8f4a7ecb064dcfbc42e2c61ba2d',
    logIndex: 0,
    id: 'log_a758f7ff'
  }
]

// 조회하려는 이벤트는 아래와 같이 Transfer 이벤트
{
    anonymous: false,
    inputs: [
        { indexed: true, name: 'from', type: 'address' },
        { indexed: true, name: 'to', type: 'address' },
        { indexed: false, name: 'value', type: 'uint256' },
    ],
    name: 'Transfer',
    type: 'event',
},

// 실제 decodeLog 사용방법
console.log(caver.abi.decodeLog([
	{ indexed: true, name: 'from', type: 'address' },
	{ indexed: true, name: 'to', type: 'address' },
	{ indexed: false, name: 'value', type: 'uint256' },
], '0x00000000000000000000000000000000000000000000000000000000000003e8', [
	'0x00000000000000000000000060498fefbf1705a3db8d7bb5c80d5238956343e5',
	'0x00000000000000000000000060498fefbf1705a3db8d7bb5c80d5238956343e5'
]))

topics의 경우 문서의 설명에 나와있듯이, anonymous 이벤트가 아닌 경우 topics의 0을 제외한 값이 파라미터로 전달되어야 합니다. 그래서 위의 예시의 경우 topics.slice(1)이 파라미터로 전달됩니다.
자세한 내용은 문서를 참고해 주시기 바랍니다.

1 Like