3

虽然我使用 Compound 的交换接口成功地铸造了测试 Dai,但在使用 Ganache 和我的本地机器时遇到了一些问题。尝试铸币时,我有以下脚本(也从教程中发布,here,关于铸币测试 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);
  });

然而,每次我运行它时,我都会得到“DAI 铸币成功”但“返回值无效,它是不是用完了气体?” 我需要明确设置 Gas 吗?

4

1 回答 1

-1

你的 ganache 是否连接到主网?

如果没有,您需要通过设置 truffle.config 将其连接到主网。如果你想在本地测试网上试用它,你需要在本地测试网上部署 dai 合约,或者你可以使用这个方便的技巧https://medium.com/@samajammin/how-to-interact-with-ethereums -mainnet-in-a-development-environment-with-ganache-3d8649df0876克隆网的当前状态

于 2020-04-22T12:32:22.220 回答