0

I have a contract template. The idea is to enable visitors to my website to customise and deploy the contract using Metamask by providing a set of constructor variables and outputting the resulting contract address after the transaction has been mined.

Can anybody point me in the right direction?

1
  • Maybe you could edit your question to point to what you actually need? I'm not sure which part of the development you need help with. It is pretty straightforward if you developed DApps using web3 library. Jun 25, 2017 at 17:00

1 Answer 1

1

You can remove a dependence on the client deploying the correct bytecode by making a factory contract for your template contract.

The factory would accept arguments and pass them on to the template's constructor.

Really simplified example here to focus on the main parts: Is There a Simple Contract Factory Pattern?

In this case, you don't deploy the template at all. You just deploy one factory contract (normally) and it keeps a list of the instance addresses for you.

Hope it helps.

5
  • 2
    Factory contracts are really cool for this, because once the factory is known and audited, people can trust any of its children! I think it's an important pattern for the long term!
    – DanF
    Jun 25, 2017 at 22:38
  • I tried the code at the link you provided, but when I execute New Cookie on the deployed contract the transaction does not create a new contract but generates an address only. Any advice?
    – Steve
    Jun 29, 2017 at 4:41
  • @Steve. Switch to Remix. You'll see the function actually returns a contract address (c). I think you're describing the transaction hash you get when you sign a transaction. It's the same for all contracts. You don't get the return values unless calling from another contract. Two options ... a) elaborate the example with an event log and then listen for a "new contract!" event, or b) wait for the transaction to be mined at then interrogate the getters that are 'constant' and will return values you can see. Jun 29, 2017 at 5:10
  • @Rob. I used Remix to deploy the Bakery which is now live at ropsten.etherscan.io/address/…
    – Steve
    Jun 29, 2017 at 5:20
  • You are right. I deployed the Bakery contract: ropsten.etherscan.io/address/… - I also published the source to make it easier to check. I then executed the New Cookie function (ropsten.etherscan.io/tx/…) When I read the contract and query '0' I get the address 0x54baf97ed3209bbca65571a88e09bd11e5f2edbd I published the contract source for the Cookie contract: ropsten.etherscan.io/address/… Checks out.
    – Steve
    Jun 29, 2017 at 5:28

Your Answer

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

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