i have contract factory which looks like following
pragma solidity ^0.4.8;
import './RentalContract.sol';
contract contractFactory {
address[] public contracts;
function getContractCount() public constant returns(uint contractCount) {
return contracts.length;
}
function newContract(uint _rent, uint _security_deposit, string _house, address _owner, address _tenant)
public constant returns(address) {
Rental c = new Rental(_rent, _security_deposit, _house, _owner, _tenant);
contracts.push(c);
return c;
}
}
this contract has a function called newContract which creates an object of another contract called RentalContract and returns the address of the newly created object. Now i want to interact with this newly created instance of Rental contract through this address using web3js. How can I achieve this?
EDIT
here is my rental contract
pragma solidity ^0.4.8;
contract Rental {
struct PaidRent {
uint id;
uint value;
}
PaidRent[] public paidrents;
uint public createdTimestamp;
uint public rent;
uint public security_deposit;
string public house;
address public owner;
address public tenant;
enum State {Created, Started, Terminated}
State public state;
function Rental(uint _rent, uint _security_deposit, string _house, address _owner, address _tenant) {
createdTimestamp = block.timestamp;
rent = _rent;
security_deposit = _security_deposit;
house = _house;
owner = _owner;
tenant = _tenant;
}
modifier require(bool _condition) {
if(!_condition) throw;
_;
}
modifier ownerOnly() {
if(msg.sender != owner) throw;
_;
}
modifier TenantOnly() {
if(msg.sender != tenant) throw;
_;
}
modifier inState(State _state){
if(_state != state) throw;
_;
}
function getPaidRents() internal returns (PaidRent[]) {
return paidrents;
}
function getHouse() constant returns (string) {
return house;
}
function getowner() constant returns (address) {
return owner;
}
function getTenant() constant returns (address) {
return tenant;
}
function getRent() constant returns (uint) {
return rent;
}
function getDeposit() constant returns (uint) {
return security_deposit;
}
function getContractCreated() constant returns (uint) {
return createdTimestamp;
}
function getContractAddress() constant returns (address) {
return this;
}
function getState() returns (State) {
return state;
}
function CollectEth() payable {}
function payRent() TenantOnly inState(State.Started) require(msg.value == rent) {
owner.transfer(msg.value);
paidrents.push(PaidRent({
id : paidrents.length + 1,
value : msg.value
}));
}
function terminateContract(address deposit_to) inState(State.Started) require(this.balance == security_deposit) {
deposit_to.transfer(security_deposit);
state = State.Terminated;
}
}
i am able to create a new instance of this rental contract thorugh contractFactory's function called newContract. i can interact with this new rental contract by var c2 = Rental.at('0x0109b453ea7734c2c32c3fc73b80de42d6e81f8e')
on truffle console. but i don't know how to do this in my angular's service using web3js. if i try to use it in the same way as truffle console it says cannot find name Rental.