gpt4 book ai didi

ethereum - 我如何使用本地主机来测试 Dai

转载 作者:行者123 更新时间:2023-12-05 08:06:19 27 4
gpt4 key购买 nike

虽然我已经成功地使用 Compound 的交换接口(interface)类型转换测试 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 mint success”,但“返回的值无效,是不是没油了?”我需要明确设置 Gas 吗?

最佳答案

你的 ganache 连接到主网了吗?

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

关于ethereum - 我如何使用本地主机来测试 Dai,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61237443/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com