본문으로 건너뛰기

Compute Contract Deployments in Block

업데이트 날짜:
2025년 11월 12일

개요

Measuring the amount of developer activity happening on a given blockchain is not straightforward. A combination of methodologies is the best way to get a comprehensive view of the blockchain's activity. One of the most important metrics is the number of smart contracts being deployed.

To get this value, many rely on data found within a block's receipts. While a good estimate and the only option for blockchains that don't support debug traces, it misses contracts deployed through other smart contracts, known as factories.

In this Function example, we will extract the number of contracts deployed through a block's traces.

Sample Function

function main(params) {
// Validate we have expected dataset
if (params.metadata?.dataset) {
if (params.metadata.dataset !== 'debug_traces') {
return {
error: 'Unexpected dataset, expected debug_traces',
}
}
}

// Extract data from params
const traces = params.data ? params.data[0] : params[0]
const blockNumber = params.metadata.batch_start_range

let numContractDeployments = 0

// Recursive function to process traces and count where type is CREATE or CREATE2
const processTrace = trace => {
const item = trace.result ? trace.result : trace
if (item.type && ['CREATE', 'CREATE2'].includes(item.type)) {
numContractDeployments++
}
if (item.calls) {
item.calls.forEach(processTrace)
}
}
traces.forEach(processTrace)

return {
network: params.metadata.network,
blockNumber,
numContractDeployments,
}
}

요청

We will invoke the function with the following cURL command. A few notes:

  • Replace the YOUR_API_KEY with your own Quicknode API key - follow this guide for creating an API key.
  • Replace the FUNCTION_ID with the ID of your Function - you can find this in the URL when viewing your Function in the Quicknode Dashboard.
  • Use the block_number parameter to specify the block number you want to analyze. You can also omit this property for the function to run against the latest block.
curl -X POST "https://api.quicknode.com/functions/rest/v1/functions/FUNCTION_ID/call?result_only=true" \
-H "accept: application/json" \
-H "Content-Type: application/json" \
-H "x-api-key: YOUR_API_KEY" \
-d '{
"network": "ethereum-mainnet",
"dataset": "debug_traces",
"block_number": 21503215
}'

답변

Resulting in the following response:

{
"network": "ethereum-mainnet",
"blockNumber": 21503215,
"numContractDeployments": 5
}

Looking to learn more about Functions? Get started here.

여러분의 피드백을 ❤️ 환영합니다!

의견이나 다루었으면 하는 새로운 주제가 있다면 알려주세요. 여러분의 의견을 기다리고 있습니다.

이 문서 공유하기