Skip to content

Instantly share code, notes, and snippets.

@mohamedhayibor
Forked from fvictorio/metadata.js
Created July 29, 2020 15:13
Show Gist options
  • Save mohamedhayibor/bf1825aa8f385a08e10dc1304f172582 to your computer and use it in GitHub Desktop.
Save mohamedhayibor/bf1825aa8f385a08e10dc1304f172582 to your computer and use it in GitHub Desktop.
const cbor = require('cbor')
const bytecode = '70656e6420696e707574206e6f7465415a54454320617272617920696e646578206973206f7574206f6620626f756e6473a265627a7a7231582011639b922cf661bed862dc70ef7a0a62211ae58261383916450efb20b2fd6a4164736f6c63430005100032'
// last two bytes are 0032, interpreted in hex is 50, so length in hex is 100
// the metadata bytes are the last 100 chars, excluding the last 4 which are the size
const metadata = bytecode.slice(bytecode.length - 104, bytecode.length - 4)
const { solc } = cbor.decode(metadata)
console.log(solc.toString('hex'));
// this logs 000510, which means solc 0.5.16 was used
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment