omg-js icon indicating copy to clipboard operation
omg-js copied to clipboard

Uncaught ReferenceError during Deposit (web3 <= v1.2.2)

Open deeintech opened this issue 4 years ago • 0 comments

Description

When running code examples as a separate project, deposit returns Uncaught ReferenceError: regeneratorRuntime preventing from executing any subsequent code. That's a direct issue of web3 that supposed to be fixed in v1.2.2 but probably was fixed in the later versions. Having up-to-date web3 dependency should fix the problem.

Expected behavior

No errors during deposit function, subsequent code runs as it should.

Actual behavior

Deposit happens but returns an issue and blocks any other code from executing.

Steps to reproduce the behavior

  1. Create a new node.js project.
  2. Install web3 <=v1.2.2 (or earlier) and other dependencies from Example folder.
  3. Modify env file or config.js directly (if env doesn't work for some reason) with required values.
  4. Create a new .js file. Instert the following code:
import BigNumber from "bn.js";
import Web3 from "web3";
import { ChildChain, RootChain, OmgUtil } from "@omisego/omg-js";
import config from "../config.js";

const web3 = new Web3(new Web3.providers.HttpProvider(config.eth_node), null, {
  transactionConfirmationBlocks: 1,
});
const rootChain = new RootChain({
  web3,
  plasmaContractAddress: config.plasmaframework_contract_address,
});
const childChain = new ChildChain({
  watcherUrl: config.watcher_url,
  watcherProxyUrl: config.watcher_proxy_url,
  plasmaContractAddress: config.plasmaframework_contract_address,
});
const aliceAddress = config.alice_eth_address;
const alicePrivateKey = config.alice_eth_address_private_key;
const depositAmount = new BigNumber(
  web3.utils.toWei(config.alice_eth_deposit_amount, "ether")
);

async function childchainDepositEth() {
  console.log(
    `Depositing ${web3.utils.fromWei(
      depositAmount.toString(),
      "ether"
    )} ETH from the rootchain to the childchain`
  );
  const transactionReceipt = await rootChain.deposit({
    amount: depositAmount,
    txOptions: {
      from: aliceAddress,
      privateKey: alicePrivateKey,
      gas: 6000000,
    },
  });
  console.log("Deposit successful: ", transactionReceipt.transactionHash);
}

childchainDepositEth();
  1. Run the code with node, webpack, browserify, or another preferable way.

Error Logs

Uncaught ReferenceError: regeneratorRuntime is not defined
    at eval (web3.min.js:4)
    at n (web3.min.js:4)

Versions

  • web3.js: 1.2.2 (and earlier versions)
  • browser: Chrome 80.0.3987.163

deeintech avatar Apr 17 '20 10:04 deeintech