I have a contract and I'm super confused how to interact with it. The submitting part works fine and I get a contract id. After that, I don't really understand if I'm supposed to send it a transaction or do something else? What's the lifecycle? It says the constructor is executed when the contract runs. When is that? When it's mined? Everytime a person sends it a message. How do I send it a message? Does the consumer of a contract send gas? The creator? Both? If two people send messages are there two contracts or one?
Using this as a base: https://gist.github.com/tomconte/4edb83cf505f1e7faf172b9252fff9bf#file-web3-solc-contract-compile-deploy-js-L20
Have this function:
function testContract(address) {
// Reference to the deployed contract
const greeter = contract.at(address);
console.log(greeter);
//console.log(greeter("bob"));
//var msg = greeter.greet.estimateGas();
//const destAccount = '0x002D61B362ead60A632c0e6B43fCff4A7a259285';
//console.log(greeter.greet.sendTransaction(destAccount));
}
I've tried greeter.greet, greeter.almosteverything.
The object for greeter looks like this:
{_eth:...
abi:
[ { constant: false,
inputs: [],
name: 'kill',
outputs: [],
payable: false,
type: 'function' },
{ constant: true,
inputs: [],
name: 'greet',
outputs: [Object],
payable: false,
type: 'function' },
{ inputs: [Object], payable: false, type: 'constructor' } ],
kill:
{ [Function: bound ]
request: [Function: bound ],
call: [Function: bound ],
sendTransaction: [Function: bound ],
estimateGas: [Function: bound ],
getData: [Function: bound ],
'': [Circular] },
greet:
{ [Function: bound ]
request: [Function: bound ],
call: [Function: bound ],
sendTransaction: [Function: bound ],
estimateGas: [Function: bound ],
getData: [Function: bound ],
'': [Circular] },
allEvents: [Function: bound ] }
Sol code:
pragma solidity ^0.4.10;
contract mortal {
/* Define variable owner of the type address*/
address owner;
/* this function is executed at initialization and sets the owner of the contract */
function mortal() { owner = msg.sender; }
/* Function to recover the funds on the contract */
function kill() { if (msg.sender == owner) selfdestruct(owner); }
}
contract greeter is mortal {
/* define variable greeting of the type string */
string greeting;
/* this runs when the contract is executed */
function greeter(string _greeting) public {
greeting = _greeting;
}
/* main function */
function greet() constant returns (string) {
return greeting;
}
}