Skip to main content

Fee Transfers

Query protocol fee transfers - the fees collected by the protocol on each transaction.

Query Structure​

query GetFeeTransfers(
$where: fee_transfers_bool_exp
$order_by: [fee_transfers_order_by!]
$limit: Int
$offset: Int
) {
fee_transfers(
where: $where
order_by: $order_by
limit: $limit
offset: $offset
) {
id
amount
sender_id
sender {
label
}
receiver_id
receiver {
label
}
block_number
block_timestamp
transaction_hash
}
fee_transfers_aggregate(where: $where) {
aggregate {
count
sum {
amount
}
}
}
}

Variables​

{
"order_by": [{ "block_timestamp": "desc" }],
"limit": 20
}

Response Fields​

FieldTypeDescription
idStringTransfer identifier
amountStringFee amount in wei
sender_idStringAccount that paid the fee
senderAccountSender account details
receiver_idStringProtocol fee receiver address
receiverAccountReceiver details
block_numberIntBlock number
block_timestampDateTimeTransfer timestamp
transaction_hashStringTransaction hash

Expected Response​

{
"data": {
"fee_transfers": [
{
"id": "0x123...-1",
"amount": "100000000000000",
"sender_id": "0xabc...",
"sender": {
"label": "alice.eth"
},
"receiver_id": "0xprotocol...",
"receiver": {
"label": "Intuition Protocol"
},
"block_number": 12345678,
"block_timestamp": "2024-01-15T10:30:00Z",
"transaction_hash": "0xdef..."
}
],
"fee_transfers_aggregate": {
"aggregate": {
"count": 5000,
"sum": {
"amount": "1500000000000000000"
}
}
}
}
}

Interactive Example​

Query

query GetRecentFees($limit: Int!) {
  fee_transfers(
    order_by: { block_timestamp: desc }
    limit: $limit
  ) {
    id
    amount
    sender {
      label
    }
    block_timestamp
  }
  fee_transfers_aggregate {
    aggregate {
      count
      sum {
        amount
      }
    }
  }
}

Variables

Click "Run Query" to execute the GraphQL query and see results

Use Cases​

Fee Revenue Dashboard​

Track protocol fee revenue:

async function getFeeRevenue(days: number = 30) {
const startDate = new Date()
startDate.setDate(startDate.getDate() - days)

const query = `
query GetFeeRevenue($start: timestamptz!) {
fee_transfers_aggregate(where: {
block_timestamp: { _gte: $start }
}) {
aggregate {
count
sum {
amount
}
}
}
all_time: fee_transfers_aggregate {
aggregate {
sum {
amount
}
}
}
}
`

const data = await client.request(query, {
start: startDate.toISOString()
})

return {
periodFees: data.fee_transfers_aggregate.aggregate.sum.amount,
periodCount: data.fee_transfers_aggregate.aggregate.count,
allTimeFees: data.all_time.aggregate.sum.amount
}
}

Top Fee Payers​

Find accounts that have paid the most fees:

async function getTopFeePayers(limit: number = 10) {
const query = `
query GetTopFeePayers($limit: Int!) {
fee_transfers(
order_by: { amount: desc }
limit: $limit
) {
amount
sender {
id
label
image
}
block_timestamp
}
}
`

return client.request(query, { limit })
}

Filtering Options​

By Date Range​

fee_transfers(where: {
block_timestamp: {
_gte: "2024-01-01T00:00:00Z",
_lte: "2024-01-31T23:59:59Z"
}
})

By Amount​

# Large fees (> 0.01 ETH)
fee_transfers(where: {
amount: { _gt: "10000000000000000" }
})

By Sender​

fee_transfers(where: {
sender_id: { _eq: "0x..." }
})

Best Practices​

  1. Aggregate for totals - Use _aggregate for sums instead of summing client-side
  2. Format amounts - Display in ETH, not wei
  3. Cache results - Fee data is historical and immutable
  4. Link to explorer - Transaction hashes can link to block explorer