[英]how to deploy contract to ganache test network and interact with it?
尝试部署合同时出现以下错误
错误:迁移尚未部署到/Users/rohank2/.nvm/versions/node/v8.11.1/lib/node_modules/truffle/build/webpack上的检测到的网络(网络/工件不匹配):
我使用松露init来创建自己的松露项目。 我初始化了一个名为Migrations的智能合约。
这是该智能合约的代码:
pragma solidity ^0.4.23;
contract Migrations{
address public admin;
struct Bank{
string bankname;
string PWCcode;
}
struct graybarbranch{
string branchname ;
uint currentapr;
uint currentdebt;
uint amtreturned;
uint totalborrowed;
string bankborrowedfrom;
}
mapping(address=>Bank) public Banks;
event graybar(address accountaddress,string branchname,uint totalamt);
mapping(address=>graybarbranch) public graybarbranches;
constructor() public {
admin =msg.sender;
}
function borrow(address from, address to,uint currentapr,uint currentamt) public {
graybarbranches[to].bankborrowedfrom=Banks[from].bankname;
graybarbranches[to].currentapr=currentapr;
graybarbranches[to].totalborrowed+=currentamt;
graybarbranches[to].currentdebt=graybarbranches[to].totalborrowed-graybarbranches[to].amtreturned;
}
function ret(address to,uint amt) public {
graybarbranches[to].amtreturned+=amt;
graybarbranches[to].currentdebt=graybarbranches[to].totalborrowed-graybarbranches[to].amtreturned;
}
function initializebank(string bankname,string PWCcode,address ad)public{
Banks[ad].bankname=bankname;
Banks[ad].PWCcode = PWCcode;
}
function initializegraybar(address ad,string branchname) public {
graybarbranches[ad].branchname=branchname;
graybarbranches[ad].currentapr=0;
graybarbranches[ad].currentdebt=0;
graybarbranches[ad].totalborrowed=0;
graybarbranches[ad].amtreturned=0;
}
function display(address ad) public{
emit graybar(ad,graybarbranches[ad].branchname,graybarbranches[ad].totalborrowed);
}
}
这是迁移文件:
var Migrations = artifacts.require("Migrations");
module.exports = function(deployer) {
deployer.deploy(Migrations);
};
最后这是我的truffle.js文件:
module.exports = {
networks: {
development: {
host: "127.0.0.1",
port: 7545,
network_id: "*"
}
}
};
不知道如何与合同互动。
要在Ganache上部署合同,请运行以下命令:$ truffle migration您将在控制台上获得txHash和合同地址。 您可以使用合同地址与Geth控制台进行交互。
要与Ganache Client交互,您必须在计算机上安装“ Geth”。
运行以下命令:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.