Query messages(events)
How to work with contract event
How to work with contract events
About messages
Account messages are of 3 types:
External inbound (
msg_type
=1 orExtIn
). It is for example, deploy message or run message.Internal message(
msg_type
=0). It is when one contract calls another contract it sends an internal message. These messages are constructed with target contract ABI. Can be of 2 subtypes:Internal inbound (
IntIn
)Internal outbound (
IntOut
)
External outbound messages(
msg_type
=2 orExtOut
). These can be of 2 subtypes:Events - these are also specified in contract ABI.
Return - these are generated by contract function's return.
Query to messages
You can fetch events of you contract like this:
query{
blockchain{
account(address:"0:1111111111111111111111111111111111111111111111111111111111111111"){
messages(msg_type:[ExtOut, ExtIn, IntIn, IntOut],first:2){
edges{
node{
body
}
cursor
}
pageInfo{
hasNextPage
}
}
}
}
}
Usage
Query
result = await client.net.query({
query: `query MyQuery($address: String!, $cursor: String, $count: Int, $start_seq_no: Int, end_seq_no: Int) {
blockchain {
account(address: $address){
messages(
master_seq_no_range: { start: $start_seq_no, end: $end_seq_no }
first: $count,
msg_type: [ExtOut, ExtIn, IntIn, IntOut],
after: $cursor
) {
edges {
node { id, created_at }
}
pageInfo {
endCursor
hasNextPage
}
}
}
}
}`,
variables:{address, cursor, count, start_seq_no, end_seq_no}
});
Decode
const decoded = (await TvmClient.default.abi.decode_message({
abi: abiContract(your-contract-abi),
message: message_boc,
}));
switch (decoded.body_type) {
case MessageBodyType.Input:
console.log(`External inbound message, function "${decoded.name}", parameters: `, JSON.stringify(decoded.value));
break;
case MessageBodyType.Output:
console.log(`External outbound message, function "${decoded.name}", result`, JSON.stringify(decoded.value));
break;
case MessageBodyType.Event:
console.log(`External outbound message, event "${decoded.name}", parameters`, JSON.stringify(decoded.value));
break;
}
Last updated