Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ethereum 如何使用本地主机测试Dai_Ethereum_Ganache - Fatal编程技术网

Ethereum 如何使用本地主机测试Dai

Ethereum 如何使用本地主机测试Dai,ethereum,ganache,Ethereum,Ganache,虽然我使用component的交换接口成功地创建了测试Dai,但在使用Ganache和我的本地机器时,我遇到了一些问题。当试图造币时,我有以下脚本(这也是从一个教程发布的,关于造币测试dai) 但是,每次运行该程序时,我都会得到“DAI mint success”,但“返回值无效,是否耗尽了汽油?”是否需要显式设置汽油 您的ganache是否连接到主网 如果没有,您需要通过设置truffle.config将其连接到mainnet。如果你想在你的本地测试网上试用它,你需要在你的本地测试网上部署da

虽然我使用component的交换接口成功地创建了测试Dai,但在使用Ganache和我的本地机器时,我遇到了一些问题。当试图造币时,我有以下脚本(这也是从一个教程发布的,关于造币测试dai)


但是,每次运行该程序时,我都会得到“DAI mint success”,但“返回值无效,是否耗尽了汽油?”是否需要显式设置汽油

您的ganache是否连接到主网


如果没有,您需要通过设置truffle.config将其连接到mainnet。如果你想在你的本地测试网上试用它,你需要在你的本地测试网上部署dai协议,或者你可以使用这个简单的技巧来克隆mainnet的当前状态你的ganache连接到mainnet了吗

如果没有,您需要通过设置truffle.config将其连接到mainnet。如果你想在你的本地测试网上试用它,你需要在你的本地测试网上部署dai协议,或者你可以使用这个简单的技巧来克隆mainnet的当前状态

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);
  });