虽然我已经成功地使用复合的交换接口创建了测试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吗?
发布于 2020-04-22 20:32:22
你的ganache连接到主网了吗?
如果没有,则需要通过设置truffle.config将其连接到主网。如果您想在本地测试网上试用它,则需要在本地测试网上部署dai合约,或者可以使用这个方便的技巧https://medium.com/@samajammin/how-to-interact-with-ethereums-mainnet-in-a-development-environment-with-ganache-3d8649df0876来克隆主机的当前状态。
https://stackoverflow.com/questions/61237443
复制相似问题