Welcome to our Help Center 👋

How to set storage fee limit dapp-side?

Written by Martin J. Maddox
Updated 5 months ago

If a dapp's smart contract is engineered in a way that involves quick changes of state in the blockchain, users' transaction can often fail because of the difference in estimated storage fees and actual storage fees at the moment when transaction is being added to the block.

To mitigate that dapp devs can employ a simple dapp-side adjustment. Temple wallet enables dapp devs to set their preferred storage fee limit.

This is completely safe as the blockchain will only charge as much as it has to, no more no less. Increasing storage fee limit will only allow to take care of minor fee fluctuations.

Here we provide a code sample that allows to set storage_limit.

You will need to use PatchedBeaconWallet instance instead of default BeaconWallet. To set storage_limit for a specific operation you will need to modify modifyFeeAndLimit function. 

This method will only work if you're using Taquito library. 
import { BeaconWallet, BeaconWalletNotInitialized } from "@taquito/beacon-wallet";
import { PermissionScope } from '@airgap/beacon-sdk';

export class PatchedBeaconWallet extends BeaconWallet {
  async sendOperations(params: any[]) {
    const account = await this.client.getActiveAccount();
    if (!account) {
      throw new BeaconWalletNotInitialized();
    }
    const permissions = account.scopes;
    this.validateRequiredScopesOrFail(permissions, [PermissionScope.OPERATION_REQUEST]);

    const { transactionHash } = await this.client.requestOperation({
      operationDetails: params.map(op => ({
        ...modifyFeeAndLimit(op),
      })) as any,
    });
    return transactionHash;
  }
}

function modifyFeeAndLimit(op: any) {
  const { fee, gas_limit, storage_limit, ...rest } = op;
  
  if (op.parameters && op.parameters.entrypoint === "buy") {
    rest.storage_limit = 310;
  }
  return rest;
}

const beaconWallet = new PatchedBeaconWallet();
// instead of `new BeaconWallet()`
In this code sample any operation where entrypoint is "buy" will be with storage_limit: 310
Did this answer your question?