TVM-Solidity-Compiler icon indicating copy to clipboard operation
TVM-Solidity-Compiler copied to clipboard

76 - Public function was called before constructor.

Open shravanandoria opened this issue 2 years ago • 5 comments
trafficstars

I'm deploying a contract from a contract. Now when calling any function from newly deployed contract I get this error code (76 - Public function was called before constructor.)

code Link Contract Factory:- https://github.com/shravanandoria/MyVenomContracts/blob/main/contracts/MarketplaceTest.tsol code Link New Contract deployed:- https://github.com/shravanandoria/MyVenomContracts/blob/main/contracts/DirectSell.tsol

This contract is deploying another contract image

This is the newly deployed contract, which causes this error (76 - Public function was called before constructor.) image

shravanandoria avatar Sep 18 '23 04:09 shravanandoria

@IgorKoval There's no solution provided for this issue in the documentation

shravanandoria avatar Sep 18 '23 04:09 shravanandoria

I've removed tvm.accept() from DirectSell Contract, still it's not working & throwing the same error

shravanandoria avatar Sep 18 '23 06:09 shravanandoria

Contract was deployed, but constructor function call wasn't successful.

When you deploy contract from contract you've send message with contract code + data and arguments to call constructor function within.

So in case there any issues in constructor function call, contract will be deployed but contructor wasn't successfuly called and you can not call any function before successful constructor function call.

Just look at first transaction on DirectSell.tsol to figure out what error code it has (look both on action and compute phase).

In your case, you've tried to reverse tvm.rawReserve(0.5 ever, 0) on children contract but only attach 0.5 ever when deploy. You'll pay for sending deploy message + gas for constructior call and after it you will not have enough value to reserve - constructor call failed.

mnill avatar Sep 18 '23 08:09 mnill

Hey, that worked!!!! @mnill but there's one thing I'm still struggling with.

Which flag should I use to reserve tokens.

if I use tvm.rawreserve with flag 0, whole contract's balance get's transferred to msg.sender, which is wrong

if I use tvm.rawreserve with flag 4, msg.value gets added to contract & child contract doesn't get deployed.

HOW CAN I SOLVE THIS!!!!

I WANT USER TO PAY FOR DEPLOYING CHILD CONTRACT & REVERSE SOME TOKENS IN THE CONTRACT, ONLY REMAINING BALANCE WHICH IS LEFT AFTER RESERVING & DEPLOYING CHILD CONTRACT SHOULD BE RETURNED TO MSG.SENDER

image

shravanandoria avatar Sep 18 '23 09:09 shravanandoria

I think such a question is not related to the compiler, and it's better to use Discord or Telegram groups to find an answer.

However, tmv.rawReserve(0.5 ever, 0) will hold 0.5 ever on your contract balance. So if there was more than 0.5 ever, the client will receive everything greater than 0.5 ever. If there was less than 0.5 ever, necessary this amount will be deducted from msg.value.

tmv.rawReserve(0.5 ever, 4) will hold the account balance plus 0.5 ever, which is deducted from msg.value.

mnill avatar Sep 18 '23 11:09 mnill