pragma solidity ^0.4.17;
contract Car{
string brand;
uint public price;
constructor(string initBrand,uint initPrice)public{
brand = initBrand;
price = initPrice;
}
function setBrand(string newBrand)public{
brand = newBrand;
}
function getBrand() public view returns (string){
return brand;
}
function setPrice(uint newPrice)public{
price = newPrice;
}
}
const fs = require('fs-extra')
const solc = require('solc')
const path = require('path')
const contractPath = path.resolve(__dirname,'../contracts','Car.sol');
const contractSource = fs.readFileSync(contractPath,'utf-8');
let compileResult = solc.compile(contractSource,1);
console.log(compileResult);
Object.keys(compileResult.contracts).forEach(name=>{
let contractName = name.replace(/^:/,'');
let filepath = path.resolve(__dirname,'../compiled',`${contractName}.json`);
fs.outputJsonSync(filepath,compileResult.contracts[name]);
console.log("Saving json file to ,"filepath);
})
const compiledPath = path.resolve(__dirname,'../compiled');
fs.removeSync(compiledPath);
fs.ensureDirSync(compiledPath);
//check errors
if(Array.isArray(result.errors) && result.errors.length){
throw new Error(result.errors[0]);
}
const fs = require('fs-extra');
const solc = require('solc');
const path = require('path');
const compiledPath = path.resolve(__dirname,'../compiled');
fs.removeSync(compiledPath);
fs.ensureDirSync(compiledPath);
//check errors
if(Array.isArray(result.errors) && result.errors.length){
throw new Error(result.errors[0]);
}
const contractPath = path.resolve(__dirname,'../contracts','Car.sol');
const contractSource = fs.readFileSync(contractPath,'utf-8');
let compileResult = solc.compile(contractSource,1);
//console.log(compileResult);
Object.keys(compileResult.contracts).forEach(name=>{
let contractName = name.replace(/^:/,'');
let filepath = path.resolve(__dirname, '../compiled', `${contractName}.json`);
fs.outputJsonSync(filepath,compileResult.contracts[name]);
console.log("Saving json file to ",filepath);
});
const Web3 = require('web3')
const web3 = new Web3(new Web3.providers.HttpProvider("Http://localhost:8545"));
const fs = require('fs-extra')
const path = require('path')
const filePath = path.resolve(__dirname,'../compiled/Car.json');
const {interface , bytecode} = require(filePath);
(async()=>{
let accounts = await web3.eth.getAccounts;
let result = await new web3.eth.Contract(JSON.parse(interface))
.deploy({data:bytecode,arguments:["BWM"]})
.send({from:accounts[0],gas:5000000});
console.log("result:",result);
})();
const Web3 = require('web3')
const web3 = new Web3(new Web3.providers.HttpProvider("Http://localhost:8545"));
const path = require('path')
const filePath = path.resolve(__dirname,'../compiled/Car.json');
const {interface , bytecode} = require(filePath);
const abi = JSON.parse(interface);
const contract = web3.eth.contract(abi);
const _from = web3.eth.accounts[0];
const txObj = {data:bytecode,from:_from,gas:5000000};
let contractInstance = contract.new(txObj,(err,res)=>{
if(err)
console.log("Error:",err);
else
console.log("Result:",res);
});