TypeError Using the EVM Decompiler on RunKit

I tried running the decompiler using this link: RunKit
and I got this error: TypeError: Cannot destructure property ‘EVM’ of ‘(intermediate value)’ as it is undefined.

Here is the code:
var evm = require(“evm”)
const { EVM } = global.EVM;
const web3 = new Web3(global.web3.currentProvider);
web3.eth.getCode(“0xC032A17BA181c17510C2bF402bd727ef72985D6B”, function(err,code) { /* DAI contract /
if(err) throw err;
const evm = new EVM(code);
console.log(evm.getFunctions()); /
Get functions /
console.log(evm.getEvents()); /
Get events /
console.log(evm.decompile()); /
Decompile bytecode */
});

The README from that package says to do:

const { EVM } =  require("evm");

Which works for me. I don’t believe global.EVM is ever set, which is why it tells you that you are trying to destructure undefined.

Thanks tolmasky. Big help.
Did you get this error? : Error: Cannot find module ‘bufferutil’

Code -
const { EVM } = require(“evm”);
const Web3 = require(‘web3’);
const web3 = new Web3(window.web3.currentProvider);
web3.eth.getCode(“0xC032A17BA181c17510C2bF402bd727ef72985D6B”, function(err,code) { /* DAI contract /
if(err) throw err;
const evm = new EVM(code);
console.log(evm.getFunctions()); / Get functions /
console.log(evm.getEvents()); / Get events /
console.log(evm.decompile()); / Decompile bytecode */
});

bufferutil is a binary package so not currently in RunKit. It does have a pure-JS fallback though, so we should be supporting it either way (we’re updating our systems to be able to do this, but it won’t help you anytime soon). A little later today I’ll try to give you a workaround though.

1 Like

Hi. Any update on the workaround?

Tolmasky? I was just wondering if there is any news for my issue.