I have following transaction logs which contains triggered event and I want to parse it:
'Program log: Instruction: Init',
'Program data: 867fyqeFJJGYZDSk+Vy/7Cpm35d+fps/e3WovaZGp4v+BTlIzV0qngEAAGXNHQAAAAA=',
'Program CBVe4r7UuJtMiBtTUXH8ic7dxqSvNcUWBNX25c2dVAYg consumed 6522 of 571982 compute units',
'Program CBVe4r7UuJtMiBtTUXH8ic7dxqSvNcUWBNX25c2dVAYg success'
This is as far as I get get with parsing:
const tx = await anchor.getProvider().connection.getTransaction(signature, {
commitment: "confirmed",
});
const log = tx.meta.logMessages[1];
const message = log.substring(log.indexOf(':')+1);
consle.log(message);
Notes:
- Event Logs are generated with emit! (which use
msq!
under hood and it's just a convenience macro for converting an arbitrary struct to a string).