1

Following the tutorial here, I know how to use oo7-parity to deploy a new contract. https://github.com/paritytech/parity/wiki/Tutorial-Part-9

deploy () {
    let tx = bonds.deployContract(CounterCode, CounterABI);

The example contract Counter has no contract constructor, so it can be deployed with only contract byte code and ABI.

However, suppose a contract has a constructor function and initialization variables like the following one, how should I put the variable (_greeting) in the bonds.deployContract function?

contract greeter{
    string greeting;
    function greeter(string _greeting) public {
        greeting = _greeting;
    }
}
1

The docs state:

You'll need to either get your own byte code from the compiler

So you can either user browser solidity or the javascript compiler.

  • Indeed, the byte code can be generated through the compiler. But the initialization variables still needs to be specified after that, even on browser solidity. photo – user2754799 Sep 7 '17 at 3:01
1

so here's how I do it. You'll need web3js 0.20.0, use it's getData function to generate the new byte code which contains encoded initialization variables.

const web3 = new Web3()
let MyContract = web3.eth.contract(MyABI)
let _greeting = "my init variable"
let newByteCode = MyContract.new.getData(_greeting, {data: oldByteCode})
let tx = bonds.deployContract(newByteCode, MyABI)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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