3

While I have be successful in minting test Dai using Compound's exchange interface, I have been having some problems when it comes to using Ganache and my local machine. When attempting to mint, I have the following script (which is also posted from a tutorial, here, regarding minting test dai)

const Web3 = require("web3");
const web3 = new Web3("http://127.0.0.1:8545");

const daiAbi = []; // left out for brevity, can be found at https://changelog.makerdao.com/ 

// Address of DAI contract
const daiMainNetAddress = "0x6B175474E89094C44Da98b954EedeAC495271d0F";

// Address of Join
const daiMcdJoin = "0x9759A6Ac90977b93B58547b4A71c78317f391A28";

let daiContract;
let accounts;

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

    // 500 DAI
    const numbDaiToMint = web3.utils.toWei("500", "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) => {
    console.log("balanceOf:", balanceOf);
    const dai = web3.utils.fromWei(balanceOf, "ether");
    console.log("DAI amount in first Ganache account wallet:", dai);
  })
  .catch((err) => {
    console.error(err);
  });

However, each time I run this, I get 'DAI mint success' but 'returned values aren't valid, did it run Out of Gas?' Do I need to explicitly set Gas?

Brennan
  • 355
  • 1
  • 5
  • 10

1 Answers1

-1

Is your ganache connected to the mainnet?

If not you need to connect it to the mainnet by setting the truffle.config. If you want to try it on your local testnet, you need to deploy the dai contracts on your local testnet, or you can use this handy trick https://medium.com/@samajammin/how-to-interact-with-ethereums-mainnet-in-a-development-environment-with-ganache-3d8649df0876 to clone the current state of the mainnet