2

I have a contract code which have getter and setter method.

I have written a java main class which done followings

TransactionReceipt receipt = sendTxAndWait(new byte[0], Hex.decode(metadata.bin));
byte[] contractAddress = receipt.getTransaction().getContractAddress();
CallTransaction.Contract contract = new CallTransaction.Contract(metadata.abi);
CallTransaction.Function inc = contract.getByName("set");
byte[] functionCallBytes = inc.encode(123);
TransactionReceipt receipt1 = sendTxAndWait(contractAddress, functionCallBytes);

Another class having below:

TransactionReceipt receipt = sendTxAndWait(new byte[0], Hex.decode(metadata.bin));
byte[] contractAddress = receipt.getTransaction().getContractAddress();
CallTransaction.Contract contract = new CallTransaction.Contract(metadata.abi);

ProgramResult r = ethereum.callConstantFunction(Hex.toHexString(contractAddress), contract.getByName("get"));
Object[] ret = contract.getByName("get").decodeResult(r.getHReturn());
System.out.println("Current contract data member value: " + ret[0]);

ProgramResult r1 = ethereum.callConstantFunction("823555f52655029e4269ccc8de2bf5d5b83936a8", contract.getByName("get"));
Object[] ret1 = contract.getByName("get").decodeResult(r1.getHReturn());
System.out.println("Executed contract data member value: " + ret1[0]);**

These two are running in two different JVM. now running second program give me output like below: Current contract data member value: 0 Executed contract data member value: 123

Now this "823555f52655029e4269ccc8de2bf5d5b83936a8" is the contract address resolved while creating contract by first java class.

So is it like that, every node want to access a contract member value should know the contract address. or is there any other way to access contract member value in ethereumj client?

1 Answer 1

2

Currently there is no other way of reffering to a contract than by it's address. This is not even a EthereumJ problem but its the way it works for the whole Ethereum Contract world.
Compare a smart contract address to a IP address. They are both machine readable and understandable but they are not easy for humans to get. Therefore your uncertainty.
Generally humans will interact over a web interface through the Mist Browser, Metamask or web3js with a smart contract. This means that they do not need to know the contract address as it is coded into the web page. Said that, I consider a domain naming service for contracts a usefull thing to have and a smart contract doing this is certainly prototyped.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.