I am practicing writing smart contracts in Solidity and running the code below results in no such file or directory error.
Error: ENOENT: no such file or directory, open 'C:\kickstart\ethereum\build:Campaign.json'
This is a Kickstarter type contract with multiple participants and a manager(owner of the contract). Users are able to donate funds. The manager is the only one who is able to withdraw money, but other user`s permission is needed for that type of action.
**Campaign.sol**
pragma solidity ^0.4.20;
contract CampaignFactory {
address[] public deployedCampaigns;
function createCampaign(uint minimum) public {
address newCampaign = new Campaign(minimum, msg.sender);
deployedCampaigns.push(newCampaign);
}
function getDeployedCampaigns() public view returns(address []) {
return deployedCampaigns;
}
}
contract Campaign {
struct Request {
string description;
uint value;
address recipient;
bool complete;
uint approvalCount;
mapping(address => bool) approvals;
}
Request[] public requests;
address public manager;
uint public minimumContribution;
//address[] public approvers; mapping has a constant time lookup
mapping(address => bool) public approvers;
uint public approversCount;
modifier restricted() {
require(msg.sender == manager);
_;
}
constructor (uint minimum, address creator) public {
manager = creator;
minimumContribution = minimum;
}
function contribute() public payable {
require(msg.value > minimumContribution);
approvers[msg.sender] = true;
approversCount++;
}
function createRequest(string description, uint value, address recipient) public restricted {
Request memory newRequest = Request({
description: description,
value:value,
recipient: recipient,
complete: false,
approvalCount:0
});
requests.push(newRequest);
}
function approveRequest(uint index) public {
Request storage request = requests[index];
require (approvers [msg.sender]);
require(!request.approvals[msg.sender]);
request.approvals[msg.sender] = true;
request.approvalCount++;
}
function finalizeRequest(uint index) public restricted {
Request storage request = requests[index];
require(!request.complete);
request.complete = true;
}
}
**compile.js**
const path = require("path");
const solc = require("solc");
//file system on local compuiter
const fs = require("fs-extra");
const buildPath = path.resolve(__dirname, "build");
// file removal in fs-extra version
fs.removeSync(buildPath);
//path to the file
const campaignPath = path.resolve(__dirname, "contracts", "Campaign.sol");
//get a content of file
const source = fs.readFileSync(campaignPath, "utf8");
// output from the compiler
const output = solc.compile(source, 1).contracts;
for (let contract in output) {
fs.outputJsonSync(
path.resolve(buildPath, contract + ".json"),
output[contract]
);
}