2_deploy_contracts.js
var Regulator = artifacts.require("./Regulator.sol");
var TollBoothOperator = artifacts.require("./TollBoothOperator.sol");
module.exports = function(deployer) {
deployer.deploy(Regulator);
var RegulatorAddress = Regulator.address;
console.log(RegulatorAddress);
deployer.deploy(TollBoothOperator, true, 50000, RegulatorAddress);
}
Here is part of my app.js
// Import the page's CSS. Webpack will know what to do with it.
import "../stylesheets/app.css";
// Import libraries we need.
import { default as Web3} from 'web3';
import { default as contract } from 'truffle-contract';
// Import our contract artifacts and turn them into usable abstractions.
import metacoin_artifacts from '../../build/contracts/Regulator.json';
import operator_artifacts from '../../build/contracts/TollBoothOperator.json';
// MetaCoin is our usable abstraction, which we'll use through the code below.
var MetaCoin = contract(metacoin_artifacts);
var Operator = contract(operator_artifacts);
// The following code is simple to show off interacting with your contracts.
// As your needs grow you will likely need to change its form and structure.
// For application bootstrapping, check out window.addEventListener below.
var accounts;
var account;
var regulator;
window.App = {
start: function() {
var self = this;
// Bootstrap the MetaCoin abstraction for Use.
MetaCoin.setProvider(web3.currentProvider);
Operator.setProvider(web3.currentProvider);
// Get the initial account balance so it can be displayed.
web3.eth.getAccounts(function(err, accs) {
if (err != null) {
alert("There was an error fetching your accounts.");
return;
}
if (accs.length == 0) {
alert("Couldn't get any accounts! Make sure your Ethereum client is configured correctly.");
return;
}
accounts = accs;
account = accounts[0];
console.log("Default account is : " + account);
});
web3.eth.defaultAccount = account;
MetaCoin.deployed().then(function (instance) {
regulator = instance.address;
console.log("Regulator address : " + regulator);
}).catch(function (e) {
console.log(e);
})
Operator.deployed().then(function (instance) {
regulator = instance.address;
console.log("TollBoothOperator address : " + regulator);
}).catch(function (e) {
console.log(e);
})
}
Lastly here is part of my TollBoothOperator.sol:
import "./Owned.sol";
import "./Regulator.sol";
import "./TollBoothOperatorI.sol";
import "./Pausable.sol";
import "./MultiplierHolder.sol";
import "./DepositHolder.sol";
import "./TollBoothHolder.sol";
import "./RoutePriceHolder.sol";
import "./Pausable.sol";
contract TollBoothOperator is Owned, Pausable, DepositHolder, TollBoothHolder,MultiplierHolder, RoutePriceHolder,TollBoothOperatorI {
mapping (bytes32 => uint) public payments; //amount paid for hash
mapping (bytes32 => address) public paymentAddress; //vehicle address who paid for hash
mapping (bytes32 => address) public entryBooths; //entry booth address for who paid for hash
//This is different hash
mapping (bytes32 => uint) public pendingTransactions; //pending payments for each entry/exit hash
mapping (bytes32 => bytes32[]) public pendingTransactionInformation;
mapping(bytes32 => address) public pendingTransactionExitBooths;
uint public collectedFees;
address regulator; // dont need this use regulated contract functions
function TollBoothOperator(bool pausedState, uint initialDeposit, address _regulator) Pausable(pausedState) DepositHolder(initialDeposit) {
regulator = _regulator;
}
}
I am able to create an TollBoothOperator contract from a method in app.js using ABI :
createNewOperator: function() {
var newOperatorAddress;
var pausedState = true;
var initialDeposit = parseInt(document.getElementById("minDeposit").value);
var _regulator = regulator;
var tollboothoperatorContract = web3.eth.contract([{"constant":true,"inputs":[{"name":"","type":"bytes32"}],"name":"entryBooths","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"bytes32"}],"name":"payments","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"tollBooth","type":"address"}],"name":"removeTollBooth","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"newOwner","type":"address"}],"name":"setOwner","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"hashedSecret","type":"bytes32"},{"name":"price","type":"uint256"},{"name":"exitAddress","type":"address"}],"name":"executeExit","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"newState","type":"bool"}],"name":"setPaused","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"entryBooth","type":"address"},{"name":"exitBooth","type":"address"},{"name":"count","type":"uint256"}],"name":"clearSomePendingPayments","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"index","type":"uint256"},{"name":"routeHash","type":"bytes32"}],"name":"remove","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"tollBooth","type":"address"}],"name":"addTollBooth","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"bytes32"}],"name":"pendingTransactionExitBooths","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"vehicleType","type":"uint256"},{"name":"mult","type":"uint256"}],"name":"setMultiplier","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"exitSecretClear","type":"bytes32"}],"name":"reportExitRoad","outputs":[{"name":"status","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"bytes32"},{"name":"","type":"uint256"}],"name":"pendingTransactionInformation","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"entryBooth","type":"address"},{"name":"exitBooth","type":"address"}],"name":"getRoutePrice","outputs":[{"name":"priceWeis","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"tollBooth","type":"address"}],"name":"isTollBooth","outputs":[{"name":"isIndeed","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"secret","type":"bytes32"}],"name":"hashSecret","outputs":[{"name":"hashed","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"vehicleType","type":"uint256"}],"name":"getMult","outputs":[{"name":"mult","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"bytes32"}],"name":"paymentAddress","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"exitSecretHashed","type":"bytes32"}],"name":"getVehicleEntry","outputs":[{"name":"vehicle","type":"address"},{"name":"entryBooth","type":"address"},{"name":"depositedWeis","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"bytes32"}],"name":"pendingTransactions","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getOwner","outputs":[{"name":"outputOwner","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"collectedFees","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"entryBooth","type":"address"},{"name":"exitSecretHashed","type":"bytes32"}],"name":"enterRoad","outputs":[{"name":"success","type":"bool"}],"payable":true,"stateMutability":"payable","type":"function"},{"constant":true,"inputs":[],"name":"getCollectedFeesAmount","outputs":[{"name":"amount","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"vehicleAddress","type":"address"}],"name":"getTypeOfVehicle","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"entryBooth","type":"address"},{"name":"exitBooth","type":"address"},{"name":"amount","type":"uint256"}],"name":"oracleSetFee","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"vehicleType","type":"uint256"}],"name":"getMultiplier","outputs":[{"name":"mult","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"isPaused","outputs":[{"name":"isIndeed","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getDeposit","outputs":[{"name":"weis","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"entryBooth","type":"address"},{"name":"exitBooth","type":"address"}],"name":"getPendingPaymentCount","outputs":[{"name":"count","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"withdrawCollectedFees","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"entryBooth","type":"address"},{"name":"exitBooth","type":"address"},{"name":"priceWeis","type":"uint256"}],"name":"setRoutePrice","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"entry","type":"address"},{"name":"exit","type":"address"}],"name":"routeHashHelper","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"depositWeis","type":"uint256"}],"name":"setDeposit","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"inputs":[{"name":"pausedState","type":"bool"},{"name":"initialDeposit","type":"uint256"},{"name":"_regulator","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"name":"vehicle","type":"address"},{"indexed":false,"name":"entryBooth","type":"address"},{"indexed":false,"name":"exitSecretHashed","type":"bytes32"},{"indexed":false,"name":"depositedWeis","type":"uint256"}],"name":"LogRoadEntered","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"exitBooth","type":"address"},{"indexed":false,"name":"exitSecretHashed","type":"bytes32"},{"indexed":false,"name":"finalFee","type":"uint256"},{"indexed":false,"name":"refundWeis","type":"uint256"}],"name":"LogRoadExited","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"exitSecretHashed","type":"bytes32"},{"indexed":false,"name":"entryBooth","type":"address"},{"indexed":false,"name":"exitBooth","type":"address"}],"name":"LogPendingPayment","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"owner","type":"address"},{"indexed":false,"name":"amount","type":"uint256"}],"name":"LogFeesCollected","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"sender","type":"address"},{"indexed":false,"name":"entryBooth","type":"address"},{"indexed":false,"name":"exitBooth","type":"address"},{"indexed":false,"name":"priceWeis","type":"uint256"}],"name":"LogRoutePriceSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"sender","type":"address"},{"indexed":false,"name":"tollBooth","type":"address"}],"name":"LogTollBoothAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"sender","type":"address"},{"indexed":false,"name":"tollBooth","type":"address"}],"name":"LogTollBoothRemoved","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"sender","type":"address"},{"indexed":false,"name":"vehicleType","type":"uint256"},{"indexed":false,"name":"multiplier","type":"uint256"}],"name":"LogMultiplierSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"sender","type":"address"},{"indexed":false,"name":"depositWeis","type":"uint256"}],"name":"LogDepositSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"sender","type":"address"},{"indexed":false,"name":"newPausedState","type":"bool"}],"name":"LogPausedSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"previousOwner","type":"address"},{"indexed":false,"name":"newOwner","type":"address"}],"name":"LogOwnerSet","type":"event"}]);
var tollboothoperator = tollboothoperatorContract.new(pausedState,initialDeposit,_regulator,{
from: web3.eth.accounts[0],
data: '',
gas: '4700000'
}, function (e, contract){
console.log(e, contract);
if (typeof contract.address !== 'undefined') {
newOperatorAddress = contract.address;
//console.log('Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash);
}
})},
I can always get Regulator to deploy but TollBoothOperator never deploys. I have tried replacing RegulatorAddress with an a set address. I have tried to use promises to wait for the first deploy. I have also tried to replace deployer.deploy() with the javascript code to deploy a new contract from ABI. Here is the error I get when trying to get contract address from Operator:
Error: Contract has not been deployed to detected network (network/artifact mismatch)