I have followed this Hardhat tutorial. But I'm modifying the config file to make it work on RSK, and have uencountered some unexpected behaviour with addresses.
const { expect } = require('chai');
describe('Token contract', () => {
it('Deployment should assign the total supply of tokens to the owner', async () => {
const [owner] = await ethers.getSigners();
console.log('Smart contract owner: ', owner.address);
const Token = await ethers.getContractFactory('Token');
const hardhatToken = await Token.deploy();
const ownerBalance = await hardhatToken.balanceOf(owner.address);
expect(await hardhatToken.totalSupply()).to.equal(ownerBalance);
});
});
Here is the hardhat.config.js
setup I am using:
require('@nomiclabs/hardhat-waffle');
const fs = require('fs');
const minimumGasPriceTestnet = 65164000;
const TESTNET_GAS_MULT = 1;
const mnemonic = fs.readFileSync('.secret', 'utf8').toString().trim();
if (!mnemonic || mnemonic.split(' ').length !== 12) {
throw new Error('unable to retrieve mnemonic from .secret');
}
module.exports = {
solidity: '0.7.3',
defaultNetwork: 'rsktestnet',
networks: {
hardhat: {},
rsktestnet: {
chainId: 31,
url: 'https://public-node.testnet.rsk.co/',
gasPrice: Math.floor(minimumGasPriceTestnet * TESTNET_GAS_MULT),
gasMultiplier: TESTNET_GAS_MULT,
accounts: {
mnemonic,
initialIndex: 0,
// Ref: https://developers.rsk.co/rsk/architecture/account-based/#derivation-path-info
path: "m/44'/37310'/0'/0",
count: 10,
},
},
},
};
In a file .secret
I store a mnemonic phrase I am also using in a web browser wallet (Metamask).
I run the test and it fails with the following error:
Token contract
Smart contract owner: 0x266f1533e637F88C8022251d5Ec9221E9.......
1) Deployment should assign the total supply of tokens to the owner
0 passing (5s)
1 failing
1) Token contract
Deployment should assign the total supply of tokens to the owner:
ProviderError: the sender account doesn't exist
at HttpProvider.request (node_modules/hardhat/src/internal/core/providers/http.ts:49:19)
at HDWalletProvider.request (node_modules/hardhat/src/internal/core/providers/accounts.ts:181:36)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at EthersProviderWrapper.send (node_modules/@nomiclabs/hardhat-ethers/src/internal/ethers-provider-wrapper.ts:13:20)
I have noticed that the contract owner address differs from the Metamask generated. Why does Hardhat and Metamask produce different account addresses. Since I'm using the same seed phrase, shouldn't both have the same addresses?