Skip to main content

Function Signature

Future<DelegationApproveResponse> approve({
  required String chain,
  required String token,
  required String delegateAddress,
  required String amount,
})

Description

Grant a delegate address permission to transfer tokens on your behalf. Works across EVM and Solana chains.

Parameters

ParameterTypeRequiredDescription
chainStringYesCAIP-2 chain ID (e.g., "eip155:11155111" for Sepolia, "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1" for Solana)
tokenStringYesToken symbol or address (e.g., "USDC")
delegateAddressStringYesThe address to delegate to
amountStringYesThe amount to delegate (e.g., "100.0")

Returns

DelegationApproveResponse - An object containing:
PropertyTypeDescription
transactionsList<DelegationConstructedTransaction?>?Array of constructed transactions (for EVM chains)
encodedTransactionsList<String?>?Array of encoded transaction strings (for Solana)
metadataDelegationApproveMetadata?Approval metadata with chain ID, delegate amount, delegate address, token symbol, etc.

Example

EVM

import 'package:portal_flutter/portal_flutter.dart';

final portal = Portal();

final response = await portal.delegations.approve(
  chain: 'eip155:11155111',
  token: 'USDC',
  delegateAddress: '0x1234...',
  amount: '100.0',
);

// Sign and send the transaction
final tx = response.transactions!.first!;
final txResponse = await portal.request(
  chainId: 'eip155:11155111',
  method: 'eth_sendTransaction',
  params: [
    {'from': tx.from, 'to': tx.to, 'data': tx.data, 'value': tx.value}
  ],
);
print('Tx hash: ${txResponse.result}');

Solana

final response = await portal.delegations.approve(
  chain: 'solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1',
  token: 'USDC',
  delegateAddress: '7smgSuU5mjP7QY5yWGdaTfgKn8hUWwvQgfvgcZB3HmJi',
  amount: '100.0',
);

// Sign and send the transaction
final encodedTx = response.encodedTransactions!.first!;
final txResponse = await portal.request(
  chainId: 'solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1',
  method: 'sol_signAndSendTransaction',
  params: [encodedTx],
);
print('Tx hash: ${txResponse.result}');

Errors

CodeDescription
NOT_INITIALIZEDPortal was not initialized
DELEGATION_FAILEDThe delegation approval failed