0

I have unsuccessfully been trying to drain accounts in the flextesa sandbox, so that all my scenarios start out in a clean state.

Taquito's documentation suggests a way https://tezostaquito.io/docs/drain_account/#draining-implicit-accounts-tz1-tz2-tz3 which, when I try it gives me

Its initial balance is 95216.777494 ꜩ.
src/ts-sdk/node_modules/@taquito/taquito/dist/taquito.umd.js:1819
                    throw new TezosOperationError(errors, 'Error occurred during estimation');
                          ^

TezosOperationError: (temporary) proto.013-PtJakart.contract.balance_too_low
    at RPCEstimateProvider.<anonymous> (src/ts-sdk/node_modules/@taquito/taquito/dist/taquito.umd.js:1819:27)
    at Generator.next (<anonymous>)
    at fulfilled (src/ts-sdk/node_modules/@taquito/taquito/dist/taquito.umd.js:41:62)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  errors: [
    {
      kind: 'temporary',
      id: 'proto.013-PtJakart.contract.cannot_pay_storage_fee'
    },
    {
      kind: 'temporary',
      id: 'proto.013-PtJakart.contract.balance_too_low',
      contract: 'tz1fwsj3KqQVZqPzzmjTreHc6W9MVhubMgHp',
      balance: '0',
      amount: '64250'
    }
  ],
  errorDetails: 'Error occurred during estimation',
  id: 'proto.013-PtJakart.contract.balance_too_low',
  kind: 'temporary'
}

Node.js v18.12.1```

Has something changed in the Tezos protocol to 

2 Answers 2

0

Thank you for reaching out with your question!

I have an example of code that should do what you are trying to achieve.

If this doesnt help you, could provide some of the code that is not working? It would help to understand where the error might be coming from.

      const receiver = new TezosToolkit('chosen rpc');
      const receiverSigner = (InMemorySigner instance for this account)
      await receiver.setSignerProvider(receiverSigner);
      const receiver_pkh = await receiver.signer.publicKeyHash();

      // create and fund the account we want to empty
      const sender = new TezosToolkit('chosen rpc');
      const senderSigner = (InMemorySigner instance for this account)
      await sender.setSignerProvider(senderSigner);
      const sender_pkh = await sender.signer.publicKeyHash();
      const op = await Tezos.contract.transfer({ to: sender_pkh, amount: 1 });
      await op.confirmation();
      
      // Sending 1 token from the account we want to empty
      // This will do the reveal operation automatically
      const op2 = await sender.contract.transfer({ to: await Tezos.signer.publicKeyHash(), amount: 0.1 });
      await op2.confirmation();

      const balance = await Tezos.tz.getBalance(sender_pkh);

      const estimate = await sender.estimate.transfer({
          to: receiver_pkh,
          amount: 0.5,
      });

      // // Emptying the account
      const totalFees = estimate.suggestedFeeMutez + estimate.burnFeeMutez;
      const maxAmount = balance.minus(totalFees).toNumber();
      // // Temporary fix, see https://gitlab.com/tezos/tezos/-/issues/1754
      // // we need to increase the gasLimit and fee returned by the estimation
      const gasBuffer = 500;
      const MINIMAL_FEE_PER_GAS_MUTEZ = 0.1;
      const increasedFee = (gasBuffer: number, opSize: number) => {
           return (gasBuffer) * MINIMAL_FEE_PER_GAS_MUTEZ + opSize
       }

      const opTransfer = await sender.contract.transfer({
           to: receiver_pkh,
           mutez: true,
           amount: maxAmount - increasedFee(gasBuffer, Number(estimate.opSize)),
           fee: estimate.suggestedFeeMutez + increasedFee(gasBuffer, Number(estimate.opSize)), // baker fees
           gasLimit: estimate.gasLimit + gasBuffer,
           storageLimit: estimate.storageLimit 
       });

       await opTransfer.confirmation();
       const finalBalance = await Tezos.tz.getBalance(sender_pkh);

Jakarta is the previous protocol than the current and is (I believe) where gas was changed from gas to milligas. So, the fees, storage, and gas amounts would differer substantially.

There is also an error with gas simulation on tezos that was discovered about a year ago and am not sure if it has been addressed. which is why there is the "// Temporary fix ..."

The work around is to add a buffer for the gas amount since it is estimated too low for what is needed. Which would explain the "balance_too_low".

If this is not quite what you need please send the code that is giving you trouble.

Please don't hesitate to reach out again!

1
  • Hi, thanks for the suggestion, it worked for me. For a more generic use I would add a check that the balance is non-zero, but otherwise you solution works! Nov 15, 2022 at 16:31
0

I have unsuccessfully been trying to drain accounts in the flextesa sandbox, so that all my scenarios start out in a clean state.

Can you expand a bit more on what you are trying to achieve? Flextesa boxes are highly customizable and you can provision them with custom accounts and properties.

1
  • I am running many scenarios in parallel with many addresses which need to start out with a zero balance at the beginning of the scenario. Since I relaunch my scenario many times, I need to drain them. By the way, could you point to a link on how to setup custom accounts in flextesa? Thanks Nov 17, 2022 at 17:38

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.