TypeError: Cannot read properties of undefined (reading 'importKey')
Dung Do Tien
Aug 28 2022
350
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.');
window.location.reload();
await walletConnect.deactivate()
return;
}
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=22.8.1.1:10 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'importKey')
at i (index.umd.js?v=22.8.1.1:10:69168)
at a (index.umd.js?v=22.8.1.1:10:69382)
at Object.o (index.umd.js?v=22.8.1.1:26:39645)
at Module.c (index.umd.js?v=22.8.1.1:26:13493)
at async t.default._encrypt (index.umd.js?v=22.8.1.1:26:31979)
at async t.default._sendRequest (index.umd.js?v=22.8.1.1:26:26020)
I run code on a local PC only. Can anyone help me?
Thanks in advance.
Have 1 answer(s) found.
-
m0
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.
* Type maximum 2000 characters.
* All comments have to wait approved before display.
* Please polite comment and respect questions and answers of others.