I am trying to get all accounts using web3@1.3.3
and @truffle/hdwallet-provider@1.2.2
. I am using HDWalletProvider
with Infura. I am running this code on backend (Node.js v14.15.5). This is the code that I have currently:
const HDWalletProvider = require('@truffle/hdwallet-provider');
const Web3 = require('web3');
const provider = new HDWalletProvider({
mnemonic: {
phrase: '... 12 words ...'
},
providerOrUrl: 'https://rinkeby.infura.io/v3/PROJECT_ID'
});
const web3 = new Web3(provider.engine);
const deploy = async (contractName) => {
try {
console.log('checkpoint 1');
web3.eth.getAccounts().then(function(e) {
console.log('checkpoint 2');
})
.catch(function(err) {
console.log('checkpoint 3');
});
} catch (err) {
console.log('Checkpoint 4');
}
};
deploy('myContract');
When I run the code, the only thing printed into console is checkpoint 1
. There is no error or exception, no indication that something wrong. Can somebody give me a hint what I am doing wrong? Why is getAccounts
not working?
EDIT
I also tried the following code (as per smarteasy suggestion), but it doesn't work either. It only prints checkpoint 1
:
const deploy = async (contractName) => {
try {
console.log('checkpoint 1');
const accounts = await web3.eth.getAccounts();
console.log('checkpoint 2');
} catch (err) {
console.log('checkpoint 3');
}
};