【问题标题】:How can I mint test Dai using local host如何使用本地主机测试 Dai
【发布时间】:2020-07-28 22:29:27
【问题描述】:

虽然我使用 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?”我需要明确设置 Gas 吗?

【问题讨论】:

    标签: ethereum ganache


    【解决方案1】:

    你的 ganache 连接到主网了吗?

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

    【讨论】:

      猜你喜欢
      • 2012-04-18
      • 2016-10-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-22
      • 1970-01-01
      • 2012-06-28
      • 1970-01-01
      相关资源
      最近更新 更多