The explorer API
Everything the block explorer displays is also available as an API. There is no key, no account and no registration: the chain is public, so the API that reads it is public too.
Base address: https://l2pscan.com
Two APIs, the same data
The REST API is the one to build on. One resource per endpoint, JSON shaped for this chain, and no legacy baggage.
The Etherscan compatible API exists so that tooling which already speaks Etherscan works here by changing one setting: the base url. Use it to point an existing integration at this chain, not to write something new.
Both are described in the interactive reference at l2pscan.com/api-docs, where you can also send requests and see the answers. See Try the API in your browser.
REST endpoints
| Endpoint | Returns |
|---|---|
/api/explorer/status |
How far the indexer has progressed, and the chain head |
/api/explorer/blocks |
The most recent blocks |
/api/explorer/blocks/{blockNumber} |
One block |
/api/explorer/blocks/{blockNumber}/transactions |
The transactions in a block |
/api/explorer/blocks/{blockNumber}/internal-transactions |
The internal transactions in a block |
/api/explorer/transactions |
The most recent transactions |
/api/explorer/transactions/{transactionHash} |
One transaction |
/api/explorer/addresses/{address} |
Balance, counts, token balances and transactions |
/api/explorer/addresses/{address}/internal-transactions |
Internal transactions of an address |
/api/explorer/addresses/{address}/token-transfers |
Token transfers of an address |
/api/explorer/tokens |
Every detected token |
/api/explorer/tokens/{address} |
One token |
/api/explorer/contracts |
Verified contracts |
/api/explorer/contracts/{address} |
One verified contract, with its source |
/api/explorer/contracts/{address}/functions |
The functions of a verified contract |
/api/explorer/validators |
The validator set, active and candidates |
/api/explorer/validators/{operatorAddress} |
One validator |
/api/explorer/statistics |
Chain statistics per hour or per day |
Two calls to get a feel for it:
curl -s 'https://l2pscan.com/api/explorer/status'
curl -s 'https://l2pscan.com/api/explorer/blocks?take=2'
Paging
The list endpoints take skip and take. Lists that grow at the head also take before and after, which page by cursor instead of by offset. Prefer the cursors when you walk a long list: an offset shifts under you every time a new block lands, a cursor does not.
curl -s 'https://l2pscan.com/api/explorer/tokens?skip=20&take=20'
Filters
/api/explorer/transactions narrows by succeeded, fromAddress, toAddress, startBlock, endBlock, startTime and endTime. /api/explorer/blocks takes the block and time ranges. /api/explorer/validators takes status and a query for the moniker or address. /api/explorer/statistics takes interval, either hour or day, and days.
curl -s 'https://l2pscan.com/api/explorer/transactions?succeeded=false&take=5'
curl -s 'https://l2pscan.com/api/explorer/statistics?interval=day&days=7'
What the numbers mean
Amounts come back unrounded, in wei wherever the chain uses wei. Nothing is formatted for display, because rounding is the caller's decision. The statistics endpoint is the exception: its amounts are already in L2P.
The Etherscan compatible API
One endpoint, /api, with module and action picking the operation.
| Module | Actions |
|---|---|
account |
balance, balancemulti, txlist, txlistinternal, tokentx, tokenbalance |
contract |
getabi, getsourcecode |
transaction |
getstatus, gettxreceiptstatus |
block |
getblockreward |
stats |
tokensupply |
curl -s 'https://l2pscan.com/api?module=block&action=getblockreward&blockno=13000000'
Every answer uses the Etherscan envelope, so check status rather than the HTTP code:
{ "status": "1", "message": "OK", "result": { } }
{ "status": "0", "message": "NOTOK", "result": "Unsupported module and action: account, nope." }
apikey is accepted and ignored, so tooling that insists on one can be pointed here unchanged. tag is accepted for the same reason, and only the latest state is served. Lists take page, offset up to 10000, sort as asc or desc, and the startblock and endblock range.
Rules of the road
This is indexed data, not the chain. The API serves what the explorer has read and stored, which is normally within a block or two of the head. /api/explorer/status tells you exactly how far behind it is. If you need the chain itself, at this instant, use the RPC described in RPC and networks.
Be reasonable. There is no key and no published quota, which is a courtesy rather than an invitation. Cache what does not change, ask for what you need rather than everything, and use the cursors for bulk work.
Old blocks do not change. Anything below the finalized block is settled, so it can be cached indefinitely.