It is the first time I do this so I have no idea what I am doing ! I am trying to call a contract's function and post data to it, this contract will then create another contract. Here is my contract how my contract looks like:
contract MedicalStaffObject {
using strings for *;
event LogCreatedTrip(address);
struct medicalStaffDetails {
string phoneNumber;
string physicalAddress;
}
medicalStaffDetails public details;
address[] public trips;
address public orgAddresses;
function MedicalStaffObject (address orgAddress, string phoneNumber, string physicalAddress){
details.phoneNumber = phoneNumber;
details.physicalAddress = physicalAddress;
orgAddresses = orgAddress;
}
function getDetails() public constant returns (string, string, address){
return (details.phoneNumber, details.physicalAddress, orgAddresses);
}
function getTrips() public constant returns (address[]){
return (trips);
}
function newTrip(address zone1, address zone2, address zone3, address zone4, bytes32 name, bytes32 startingDate, uint duration) public returns(address){
TripObject newTrip = new TripObject(zone1, zone2, zone3, zone4, name, startingDate, duration);
trips.push(newTrip);
LogCreatedTrip(newTrip);
return newTrip;
}
}
And I am trying to call the function newTrip using this code in my NodeJS app:
var web3 = new Web3();
web3.setProvider(new web3.providers.HttpProvider(provider));
var zonesTrimed = zones.slice(1, -1);
var zonesArray = zonesTrimed.split(",");
var contractAbi = web3.eth.contract(ethContracts.abiMedicalStaffObject);
var myContract = contractAbi.at(address);
// suppose you want to call a function named newTrip of myContract
var getData = myContract.newTrip.getData(zonesArray[0], zonesArray[1], zonesArray[2], zonesArray[3], name, startDate, duration);
//finally paas this data parameter to send Transaction
web3.eth.sendTransaction({to:address, from:organisationWallet, data: getData});
However it just doesnt work and I keep getting this error:
Error: unknown account
First of all what does this error mean, does it mean it cann't find the 'to' or the 'from' account ? What I am supposed to put in there ?
myContract.newTrip.sendTransaction(zonesArray[0], zonesArray[1], zonesArray[2], zonesArray[3], name, startDate, duration, {from: web3.eth.coinbase, value : 120000})
Try this and let me know the result.personal.unlockAccount(eth.coinbase, 'your password', duration)
on your node