JSON-RPC call to a contract constructor

I'm trying to create a contract using the JSON RPC. I understand how it's done in general (pass the contract's code as the 'data' parameter), but what if I'd like to pass additional parameters to the contract's constructor?

Here's my code:

contract Asset { ... some code here .. function Asset(string _name, uint _supply) { tokenName = _name; ... more code here ... } ...

The question, then, is how do I use the JSON-RPC eth_sendTransaction to pass the _name and _supply arguments to the constructor of 'asset'.

Comments

  • frankalfrankal Member Posts: 4
    edited November 2015
    Hi,
    we call a function : register(bytes32 hash, bytes32 date) via JSON RPC. The data element is 0x<32 characters for first parameter "hash"><32 characters for second parameters "date">. We debugged the cosmo meteor client :-)
    ciao Frank
  • frankalfrankal Member Posts: 4
    Hi,
    it's 0x, then 8 characters hash of function signiture (in our case register(bytes32 hash, bytes32 date)), then 32... see above
    ciao Frank
  • ILethereumILethereum Member Posts: 34
    I have similar question. I'm able to register, call contract API using web3. I would like to do the same from a Java service over JSON RPC. Can it be done ?
  • oliverkxoliverkx Member Posts: 85
    Same here. I am working on a .Net wrapper around the geth JSON-RPC API. I am able to invoke basic functions, but so far have been unable to invoke contracts. I think I'm close, but something is wrong, because the only result I ever get back (for contracts) is '0x'.

    Would someone be able to post a sample JSON string that would invoke a method on an existing contract in the public block-chain (and return a valid result)? Also, I am not sure if I am calculating my function hash correctly (I am currently using geth's own web3_sha3 method - really slow and inefficient - would like a native .Net equivalent).

    If I am successful with this .Net wrapper, I will post it to the community. Unless there is already something similar out there, I would be very happy to hear!

    Thank you all!
  • oliverkxoliverkx Member Posts: 85
    Also, if anyone has a piece of C# (or similar) code that would be able to consume Ethereum Contract ABI data and use it to help invoke contract methods, that would be even better!
  • ropod7ropod7 TallinMember Posts: 11 ✭✭
    Is there any solution to realise that contract creation?
  • ropod7ropod7 TallinMember Posts: 11 ✭✭
    There looks that it might be created by pushing to the end of contract code additional parameters:
    https://github.com/ethereum/wiki/wiki/JavaScript-API#web3ethcontract
    e.g.:
    var contractData = MyContract.new.getData([contructorParam1] [, contructorParam2], {data: '0x12345...'});

    Same logic as with functions, but as first parameter should be given full contract code.
Sign In or Register to comment.