1

I'm using truffle develop to interact with the MetaCoin tutorial contract. I've done this before months ago on an older version of truffle and this worked fine.

But now, I'm getting the same error every time I try to use await. I've tried a completely fresh install of the MetaCoin app following the tutorial and my own contract written from scratch, nothing is working.

truffle(develop)>  let accounts = await web3.eth.getAccounts()
Uncaught ReferenceError: global is not defined
at evalmachine.<anonymous>:2:19
truffle(develop)> let x = await MetaCoin.deployed()
Uncaught ReferenceError: global is not defined
at evalmachine.<anonymous>:2:19
truffle(develop)> let newInstance = await MetaCoin.new()
Uncaught ReferenceError: global is not defined
at evalmachine.<anonymous>:2:19

I've tried this on both of the following environments:

Truffle v5.4.5 (core: 5.4.5)
Solidity v0.5.16 (solc-js)
Node v15.5.0
Web3.js v1.5.1

Truffle v5.4.5 (core: 5.4.5)
Solidity v0.5.16 (solc-js)
Node v16.6.1
Web3.js v1.5.1

What could be wrong here?

1 Answer 1

0

The solution seems to be setting global, since it's not defined. Setting global = globalThis fixed my issues.

Here's why this works:

The globalThis property provides a standard way of accessing the global this value (and hence the global object itself) across environments. Unlike similar properties such as window and self, it's guaranteed to work in window and non-window contexts. In this way, you can access the global object in a consistent manner without having to know which environment the code is being run in.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.