1

I have a Contract Template (Say contract ABC). The constructor takes in 3 fields to initialize a contract. I built in logic within the constructor to return a bool based on data checks. The constructor should fail and not create a valid Contract if the data fields fails validation. The return is a bool.

function ABC(bytes32 _field1, bytes32 _field2, bytes32 _field3) returns (bool isSuccess);

Now when I try to create a new contract (from another contract): How do I check for the bool (Success).

I create an instance of the contract as:

ABC local = new ABC(_field1, _field2, _field3);

Is there a way to check if this was success - based on the bool return from the Constructor.

Alternative 1: I can do the data checks before I send the request to the Constructor. I was trying to avoid rewriting the same code in multiple locations.

Alternative 2: I can initialize a field isValue within the constructor and check for it when validating an instance.

Any advise? Thanks,

1 Answer 1

1

First, its worth noting that if something throws or causes an error the contract creation will automatically fail. If it does fail, you won't be able to return false anyways since all state is reverted.

Because of this, its best to simply use require or assert statements to throw if data is invalid which will cease contract creation and invalid contracts will never be created.

Alternative 1: I would recommend doing this anyways so you don't waste gas. Contract creation currently costs $5+ USD which will be wasted if you don't.

Alternative 2: You could do this, but this in inefficient since this stored data isn't actually needed.

0

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.