If i have a solidity code, which has 2 or 3 contract in it, which depends on each other, How do we deploy such contracts. As when we put this code in browser-solidity, we get different Bytecode and Interface for all the contracts separately. This might be a very stupid question. But how do we deploy these?
One by One ?
Or is there a way to deploy all at once ?
Example code which i picked from documentation.
pragma solidity ^0.4.11;
contract owned {
function owned() { owner = msg.sender; }
address owner;
modifier onlyOwner {
require(msg.sender == owner);
_;
}
}
contract mortal is owned {
function close() onlyOwner {
selfdestruct(owner);
}
}
contract priced {
modifier costs(uint price) {
if (msg.value >= price) {
_;
}
}
}
contract Register is priced, owned {
mapping (address => bool) registeredAddresses;
uint price;
function Register(uint initialPrice) { price = initialPrice; }
function register() payable costs(price) {
registeredAddresses[msg.sender] = true;
}
function changePrice(uint _price) onlyOwner {
price = _price;
}
}
contract Mutex {
bool locked;
modifier noReentrancy() {
require(!locked);
locked = true;
_;
locked = false;
}
function f() noReentrancy returns (uint) {
require(msg.sender.call());
return 7;
}
}
The way i deploy the contract:
var myContract = web3.eth.contract(ABI);
var contractInstance = myContract.new(
{
from: web3.eth.accounts[0],
data: byteCode,
gas: '4700000'
}, function (e, contract){
console.log(e, contract);
if (typeof contract.address !== 'undefined') {
console.log('Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash);
}
})
And In this i can put ABI and ByteCode for one one contract at once.