Using in Transactions

This guide demonstrates how to use the fee abstraction module with the cheqd SDK for both standard Cosmos SDK transactions and identity transactions (DIDs and DID-Linked Resources).

Fee abstraction allows users to pay transaction fees in alternative tokens (like IBC tokens from other chains) instead of the native CHEQ token, making the network more accessible to users from different ecosystems.

Prerequisites

Before using fee abstraction, ensure you have:

  1. A funded wallet with the alternative token for fee payment

  2. Access to a cheqd network with fee abstraction enabled

  3. Understanding of the available host zones and supported tokens

  4. Important: Your account must be funded with the bridged IBC representation of assets (e.g., transferred from Osmosis to cheqd) for fee abstraction to work

Note: Fee amounts in examples require manual conversion from CHEQ equivalent at current exchange rates. An upcoming SDK release will introduce USD fixed pricing and built-in price aggregation for automated fee calculation.

SDK Initialization with Fee Abstraction

import { 
  createCheqdSDK, 
  DIDModule,
  ResourceModule,
  FeeabstractionModule,
  FeemarketModule,
  CheqdNetwork,
  AbstractCheqdSDKModule,
  type ICheqdSDKOptions 
} from '@cheqd/sdk';
import { DirectSecp256k1HdWallet } from '@cosmjs/proto-signing';

async function initializeSDKWithFeeAbstraction() {
  const wallet = await DirectSecp256k1HdWallet.fromMnemonic(
    'your twelve word mnemonic phrase goes here like this example', 
    { prefix: 'cheqd' }
  );

  const options: ICheqdSDKOptions = {
    modules: [
      DIDModule as unknown as AbstractCheqdSDKModule,
      ResourceModule as unknown as AbstractCheqdSDKModule,
      FeeabstractionModule as unknown as AbstractCheqdSDKModule,
      FeemarketModule as unknown as AbstractCheqdSDKModule
    ],
    rpcUrl: 'https://rpc.cheqd.network',
    network: CheqdNetwork.Testnet,
    wallet: wallet
  };

  const sdk = await createCheqdSDK(options);
  
  return { sdk, wallet };
}

Standard Cosmos SDK Transactions

Token Transfer (Bank Module)

Staking Delegation

Claiming Rewards

Identity Transactions (DID and DLR)

DID Creation with Fee Abstraction

DID Update with Fee Abstraction

DID-Linked Resource Creation with Fee Abstraction

Image Resource Creation with Fee Abstraction

Fee Abstraction Management

Query Available Host Zones and Supported IBC Tokens

Complete Working Example

Here's a complete example that demonstrates the full workflow:

Best Practices

Fee Management

  1. Token Selection: Choose widely accepted IBC tokens with good liquidity

  2. Fee Estimation: Use dynamic fee calculation based on current market rates

  3. Fallback Strategy: Always have native CHEQ tokens as a backup payment method

  4. Cost Monitoring: Monitor fee costs across different tokens to optimize expenses

Transaction Optimization

  1. Batch Operations: Group multiple messages to reduce fee overhead

  2. Gas Estimation: Use accurate gas estimation to avoid overpaying

  3. Retry Logic: Implement retry mechanisms for failed transactions

  4. Fee Calculation: Use FeemarketModule for dynamic fee calculation

Security Considerations

  1. Private Key Management: Securely store and handle private keys

  2. Transaction Validation: Validate transaction parameters before signing

  3. Network Selection: Use appropriate network (testnet for development)

  4. Error Handling: Implement comprehensive error handling

Troubleshooting

Common Issues

  1. Insufficient Funds: Ensure wallet has enough alternative tokens for fees

  2. Invalid IBC Denom: Verify IBC denomination is correct for the target chain

  3. Gas Estimation: Use appropriate gas limits for different transaction types

  4. Host Zone Configuration: Ensure the alternative token's host zone is properly configured

Error Resolution

Next Steps

After implementing fee abstraction:

Getting Help

If you encounter issues:

Last updated

Was this helpful?