Skip to content

Instantly share code, notes, and snippets.

@cylim
Created March 7, 2022 15:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cylim/d73f890cd856743c706b91bb37ac5890 to your computer and use it in GitHub Desktop.
Save cylim/d73f890cd856743c706b91bb37ac5890 to your computer and use it in GitHub Desktop.
const ONEUtil = require('./util')
const EventMessage = require('./event-message')
const EventMaps = require('./events-map.json')
const axios = require('axios')
// Different smart contract, different address, used to determined whether it is.
const CONTRACT_ADDRESS = ['one1erxse89x3wzn7uu30smwjfm8wz5d3e8quuvkgq', 'one1wsawrzv304dhvt8dh3gl438qckklgvfjgx2xj4']
const getTx = async (hash) => {
const { data } = await axios.post('https://api.s0.t.hmny.io', {
jsonrpc: '2.0',
method: 'hmyv2_getTransactionReceipt',
params: [hash],
id: 1
})
if (CONTRACT_ADDRESS.indexOf(data.result.from) > -1 || CONTRACT_ADDRESS.indexOf(data.result.to) > -1) {
const messages = data.result?.logs
?.flatMap(l => l?.topics?.map(t => EventMessage?.[EventMaps?.[t]]?.message))
.filter(Boolean)
return {
...data.result,
errors: messages,
success: messages.length < 1
}
}
return data.result
}
const main = async () => {
const hash = '0xf8df31786cd99db6532aa84459edb2fac0e352390852c25796cf1857e7000ede'
const tx = await getTx(hash)
console.log(tx)
}
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment