3

It's my first question here so please don't be so strict.

I have such a scenario:

I start learning how blockchain works, downloaded truffle, ganache cli, created an account on infura and all that stuff to set up the environment. To create a fork I use such a command

"ganache-cli -f "URL" -p 7545 -u 0x9759A6Ac90977b93B58547b4A71c78317f391A28 -m "mnemonic" -d --db="./data/save"

and it works well. I use "-u 0x9759A6Ac90977b93B58547b4A71c78317f391A28" to unlock the address to be able to mint dai tokens and also use "--db="./data/save"" to save chain state locally to not to create new accounts each time when I restart ganache. The problem appears when I close the ganache and start it again with the command above. I get this message

Listening on 127.0.0.1:7545
eth_blockNumber
eth_getBlockByNumber
Error: Incompatible EIP155-based V 1 and chain id 1. See the second parameter of the 
Transaction constructor to set the chain id.

I tried to start ganache without "--db="./data/save"" but it create new accounts each time.

I tried to start ganache without -f "URL".(I thought that it would take data from local database) but it throws such an exception

Error: Returned error: VM Exception while processing transaction: revert Dai/not-authorized

That's how I mint dai

const Web3 = require('web3');
const web3 = new Web3('http://127.0.0.1:7545');

const daiAbi = require('./dai-abi.json');

// Address of DAI contract 
https://etherscan.io/address/0x6b175474e89094c44da98b954eedeac495271d0f
const daiMainNetAddress = '0x6b175474e89094c44da98b954eedeac495271d0f';

// Address of Join (has auth) https://changelog.makerdao.com/ -> releases -> contract 
addresses -> MCD_JOIN_DAI
const daiMcdJoin = '0x9759A6Ac90977b93B58547b4A71c78317f391A28';

let daiContract;
let accounts;

web3.eth.getAccounts().then((ganacheAccounts) => {
accounts = ganacheAccounts;
daiContract = new web3.eth.Contract(daiAbi, daiMainNetAddress);

// 1000 DAI
const numbDaiToMint = web3.utils.toWei('1000', 'ether');

return daiContract.methods.mint(accounts[0], numbDaiToMint)
    .send({
        from: daiMcdJoin,
        gasPrice: web3.utils.toHex(0)
    });
}).then(() => {
   console.log('DAI mint success');
   return daiContract.methods.balanceOf(accounts[0]).call();
}).then((balanceOf) => {
   const dai = balanceOf / 1e18;
   console.log('DAI amount in first Ganache account wallet:', dai);
}).catch((err) => {
   console.error(err);

});

Looks like the address 0x9759A6Ac90977b93B58547b4A71c78317f391A28 does not exist in my chain at all however I used "--db="./data/save"" to save chain state.

Honestly, I will not wait just solutions for this case. I really would like to understand why these exceptions happen.

How to fork with ganache correctly.

How db="./data/save" save chain state.

If someone faced with such problems, could you please share sources with the information provided or just explain how things work here.(I searched the whole Internet and of course have a little perspective how it works but still get errors and do not fully understand why) I would appreciate it. Thanks to everyone!

1
  • Does the -f parameter include a block number? I'd guess that for using --db parameters it has to start from the same block.
    – Ismael
    Commented Dec 15, 2021 at 2:20

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.