Hey I am making a smart contract that create another smart contracts. Organization.sol create Session.sol . When I create a session using createdSession function I got it's address and I already had the abi. Now I need to deploy the contract from the browser(to use function like take_feedback or seeResult). Could anyone tell me how please.
I run my contract in localhost using truffle develop
command and MetaMask.
Solidity code
pragma solidity 0.5.0;
//Session
contract Session {
address public creator; // The address of parent Organization
string sessionName;
string description;
uint startTime;
uint endTime;
address[] lecturer;
address[] attendes;
int[] result;
mapping(address => int) public attendes_feedback; //institution boardMembers
modifier onTime(uint _startTime){
require(now < _startTime);
_;
}
constructor (string memory _sessionName, string memory _description, uint _startTime,uint _endTime,address[] memory _lecturer,address[] memory _attendes) public onTime(_startTime){
sessionName = _sessionName;
description = _description;
startTime = _startTime;
endTime = _endTime;
attendes = _attendes;
lecturer = _lecturer;
initAttendes(attendes);
}
function initAttendes(address[] memory _attendes) private{
for(uint i=0 ; i < _attendes.length ; i++){
attendes_feedback[_attendes[i]] = -1;
}
}
function Time() public view returns (bool){
return (now >= startTime && now <= endTime);
}
modifier checkTime(){
require(Time());
_;
}
function take_feedback(address _voter,uint8 _feedback) public checkTime {
require(attendes_feedback[_voter] != 0);
attendes_feedback[_voter] = _feedback;
result[_feedback]++;
}
function seeResult() public view returns(int[] memory){
return result;
}
}
contract Organization {
address creator;
event sessionnCreated(string name,address sessionAddress ,address creator);
/* modifier onlyCreator(){
require(msg.sender == creator);
_;
} */
function createdSession(
string memory _sessionName,
string memory _description,
uint _startTime,
uint _endTime,
address[] memory _lecturer,
address[] memory _attendes
) public returns(address) {
Session sessionAddress = new Session(_sessionName , _description , _startTime , _endTime, _lecturer,_attendes );
emit sessionnCreated(_sessionName,address(sessionAddress),creator);
return address(sessionAddress);
}
}
Web3js Code
initSession: async function(_address) {
var abi = web3.eth.contract(SessionArtifact.abi);
var session = abi.at(_address);
alert("your session is created!!")
/*Deploy Contract here!*/
//need to deploy contract first before calling functions
/*Call function */
await session.take_feedback('0xa8ff46045fa2c6a0af361819b62126e1b0ec8909', 5).send({ from: this.account });
},