Smart contract questions

I have a handful of questions below, with some example data at the top to help make my questions a bit more clear.


Solidity code:

contract TestObject {

address sender;

uint data;

function TestObject() {

sender = msg.sender;

}

function set(uint x) {

if (msg.sender != sender) return;

data = x;

}

function get() constant returns (uint retVal) {

return data;

}

}


Hex:

60056011565b609080601f6000396000f35b336000819060000155505b5600600160008035811a818181146018578301818114602857005b601e6082565b8060005260206000f35b60316001356037565b60006000f35b60005473ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614156070576074565b607f565b806001819060000155505b50565b60006001549050608d565b9056


Results of publishing transaction:

tx hash: af5c9276edf4abfab86fa8d4df7dde0f84f17679551b8bb1cf9b8288f87d7e57

address: mqGf3q3TmSo1HbLium8tgqbxpdFpkXybyN

contract id: d6c394dd8212c1e7e54628114e055068aba69422


Questions:

  1. How is the contract id created?
  1. How do I call the TestObject constructor (function TestObject() )?
  1. After instantiating TestObject how do I call it’s methods (The functions set and get)?
  1. Counterparty-cli.py execute seems like it should be able to call a particular method from my contract, but I can't figure out how to specify the method name which makes me think that it doesn't do what I hoped it would. How do I use execute?


Next questions are about a second contract trying to reference the first:

contract TestContract {

address testObjectAddress;

TestObject testObject;

function TestContract() {

testObjectAddress = 0xd6c394dd8212c1e7e54628114e055068aba69422;

TestObject testObject = TestObject(testObjectAddress);

}

function getFromTestObject() {

uint data = testObject.get();

}

}

contract TestObject {

function TestObject() {}

function set(uint x) {}

function get() constant returns (uint retVal) {}

}


Questions:

  • What should testObjectAddress be (is it mqGf3q3TmSo1HbLium8tgqbxpdFpkXybyN, or d6c394dd8212c1e7e54628114e055068aba69422, or neither?)

Made a bit of progress here, it seems like what I’ve been thinking of as the constructor method ( function TestObject() ) is more like the init code you would see in a serpent contract which I believe is run at the time of contract creation (publish).

  1. How is the contract id created?
    This is still an outstanding question.
  2. How do I call the TestObject constructor (function TestObject() )?
    A: Publishing the contract does this for us.
  3. After instantiating TestObject how do I call it’s methods (The functions set and get)?
    A: https://github.com/ethereum/wiki/wiki/Ethereum-Contract-ABI explains how to encode the message in the payload
  4. Counterparty-cli.py execute seems like it should be able to call a particular method from my contract, but I can't figure out how to specify the method name which makes me think that it doesn't do what I hoped it would. How do I use execute?
    A: The link in the answer for question three answers this as well.
  5. What should testObjectAddress be (is it mqGf3q3TmSo1HbLium8tgqbxpdFpkXybyN, or d6c394dd8212c1e7e54628114e055068aba69422, or neither?)
    This is still an outstanding question.