TypeError: Cannot read properties of undefined (reading 'importKey')

Dung Do Tien Aug 28 2022 526

Hi everyone, I created an Html page to help connect to Defi Wallet, I want to create a button and when someone clicks on it, It will help them connect to their Defi wallet, same with MetaMask. I do like this:

Step 1: Import Defi & Web3js in to Html page

 <script type="module" src="https://unpkg.com/deficonnect/dist/index.umd.js"></script>
<script src="/custom/web3.min.js"></script>

Step 2: Connect to Defi wallet

 try {
    walletConnect = null;
    walletConnect = new window.DeFiConnect.DeFiWeb3Connector({
        supportedChainIds: [25],
        rpc: {
            25: "https://evm.cronos.org/"
        pollingInterval: 15000

    await walletConnect.activate();
    const provider = await walletConnect.getProvider();
    web3ojb = new Web3(provider);
    typeOfLogin = type;
} catch (err) {
    console.log('Error from Defi wallet: ' + err);
    alert('Failed to establish a connection to DeFi Wallet.');
    await walletConnect.deactivate()

But when run this code I got an exception threw Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'importKey'). Here is the detail:

 index.umd.js?v= Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'importKey')
    at i (index.umd.js?v=
    at a (index.umd.js?v=
    at Object.o (index.umd.js?v=
    at Module.c (index.umd.js?v=
    at async t.default._encrypt (index.umd.js?v=
    at async t.default._sendRequest (index.umd.js?v=

I run code on a local PC only. Can anyone help me?

Thanks in advance.

Have 1 answer(s) found.
  • m

    mad Aug 28 2022

    This error is thrown because you are running on HTTP but It's requires running on HTTPs.

    Tips: If you use javascript only, you can use Visual Code to help run as live server with full Https.

Leave An Answer
* NOTE: You need Login before leave an answer

* Type maximum 2000 characters.

* All comments have to wait approved before display.

* Please polite comment and respect questions and answers of others.

Popular Tips

X Close