From 3aa480c8e6d977d6320ac1827ec1b0169978b507 Mon Sep 17 00:00:00 2001 From: Mike Purvis Date: Fri, 24 Apr 2026 08:04:24 -0700 Subject: [PATCH] default to url param ?apiKey for examples, mentioning auth Bearer token ppl can use too --- docs/api/examples.md | 38 ++++------------- docs/fastdata/kv/examples.md | 23 +++-------- docs/neardata/examples.md | 36 +++++----------- docs/rpc/examples.md | 41 ++++++------------- docs/transfers/examples.md | 20 +++------ docs/tx/examples.md | 37 ++++------------- .../current/api/examples.md | 38 ++++------------- .../current/fastdata/kv/examples.md | 23 +++-------- .../current/neardata/examples.md | 36 +++++----------- .../current/rpc/examples.md | 41 ++++++------------- .../current/transfers/examples.md | 20 +++------ .../current/tx/examples.md | 37 ++++------------- 12 files changed, 102 insertions(+), 288 deletions(-) diff --git a/docs/api/examples.md b/docs/api/examples.md index 1c6146f..2392c7c 100644 --- a/docs/api/examples.md +++ b/docs/api/examples.md @@ -10,7 +10,7 @@ page_actions: ## Examples -All shell examples below work on the public FastNear API hosts as-is. If `FASTNEAR_API_KEY` is set in your shell, they add it as a bearer header automatically; if it is unset, they fall back to the public unauthenticated path. +All shell examples below work on the public FastNear API hosts as-is. If `FASTNEAR_API_KEY` is set in your shell, they pass it as an `apiKey` query parameter automatically; if it is unset, they fall back to the public unauthenticated path. Bearer auth with `Authorization: Bearer ${FASTNEAR_API_KEY}` is also supported when headers fit your client better. ### Summarize one account in one call @@ -18,11 +18,8 @@ All shell examples below work on the public FastNear API hosts as-is. If `FASTNE ```bash ACCOUNT_ID=root.near -AUTH_HEADER=() -if [ -n "${FASTNEAR_API_KEY:-}" ]; then AUTH_HEADER=(-H "Authorization: Bearer $FASTNEAR_API_KEY"); fi -curl -s "https://api.fastnear.com/v1/account/$ACCOUNT_ID/full" \ - "${AUTH_HEADER[@]}" \ +curl -s "https://api.fastnear.com/v1/account/$ACCOUNT_ID/full?apiKey=${FASTNEAR_API_KEY:-}" \ | jq '{ account_id, near_balance_yocto: .state.balance, @@ -40,18 +37,14 @@ Look up which account a key belongs to, then read that account's holdings in one ```bash PUBLIC_KEY='ed25519:CCaThr3uokqnUs6Z5vVnaDcJdrfuTpYJHJWcAGubDjT' -AUTH_HEADER=() -if [ -n "${FASTNEAR_API_KEY:-}" ]; then AUTH_HEADER=(-H "Authorization: Bearer $FASTNEAR_API_KEY"); fi -LOOKUP="$(curl -s "https://api.fastnear.com/v1/public_key/$(jq -rn --arg k "$PUBLIC_KEY" '$k | @uri')" \ - "${AUTH_HEADER[@]}")" +LOOKUP="$(curl -s "https://api.fastnear.com/v1/public_key/$(jq -rn --arg k "$PUBLIC_KEY" '$k | @uri')?apiKey=${FASTNEAR_API_KEY:-}")" echo "$LOOKUP" | jq '{matched: (.account_ids | length), account_ids}' ACCOUNT_ID="$(echo "$LOOKUP" | jq -r '.account_ids[0]')" -curl -s "https://api.fastnear.com/v1/account/$ACCOUNT_ID/full" \ - "${AUTH_HEADER[@]}" \ +curl -s "https://api.fastnear.com/v1/account/$ACCOUNT_ID/full?apiKey=${FASTNEAR_API_KEY:-}" \ | jq '{account_id, state, tokens: (.tokens|length), nfts: (.nfts|length), pools: (.pools|length)}' ``` @@ -63,11 +56,8 @@ NEAR account state has three buckets that wallet UIs tend to conflate: `balance` ```bash ACCOUNT_ID=root.near -AUTH_HEADER=() -if [ -n "${FASTNEAR_API_KEY:-}" ]; then AUTH_HEADER=(-H "Authorization: Bearer $FASTNEAR_API_KEY"); fi -curl -s "https://api.fastnear.com/v1/account/$ACCOUNT_ID/full" \ - "${AUTH_HEADER[@]}" \ +curl -s "https://api.fastnear.com/v1/account/$ACCOUNT_ID/full?apiKey=${FASTNEAR_API_KEY:-}" \ | jq ' (.state.balance | tonumber) as $amount | (.state.locked | tonumber) as $locked @@ -97,11 +87,8 @@ Every entry under `/full`'s `tokens`, `nfts`, and `pools` arrays carries its own ```bash ACCOUNT_ID=root.near -AUTH_HEADER=() -if [ -n "${FASTNEAR_API_KEY:-}" ]; then AUTH_HEADER=(-H "Authorization: Bearer $FASTNEAR_API_KEY"); fi -curl -s "https://api.fastnear.com/v1/account/$ACCOUNT_ID/full" \ - "${AUTH_HEADER[@]}" \ +curl -s "https://api.fastnear.com/v1/account/$ACCOUNT_ID/full?apiKey=${FASTNEAR_API_KEY:-}" \ | jq ' [ (.tokens // [])[].last_update_block_height, @@ -129,11 +116,8 @@ NEAR account names encode a hierarchy: `mint.sharddog.near` is a subaccount of ` ```bash ACCOUNT_ID=root.near PUBLISHER=sharddog.near -AUTH_HEADER=() -if [ -n "${FASTNEAR_API_KEY:-}" ]; then AUTH_HEADER=(-H "Authorization: Bearer $FASTNEAR_API_KEY"); fi -curl -s "https://api.fastnear.com/v1/account/$ACCOUNT_ID/nft" \ - "${AUTH_HEADER[@]}" \ +curl -s "https://api.fastnear.com/v1/account/$ACCOUNT_ID/nft?apiKey=${FASTNEAR_API_KEY:-}" \ | jq --arg publisher "$PUBLISHER" ' ("." + $publisher) as $suffix | { @@ -162,13 +146,9 @@ Direct pool positions live on `/staking`; liquid staking tokens (stNEAR, LiNEAR, ```bash ACCOUNT_ID=root.near LIQUID_PROVIDERS_JSON='["meta-pool.near","lst.rhealab.near","linear-protocol.near"]' -AUTH_HEADER=() -if [ -n "${FASTNEAR_API_KEY:-}" ]; then AUTH_HEADER=(-H "Authorization: Bearer $FASTNEAR_API_KEY"); fi -STAKING="$(curl -s "https://api.fastnear.com/v1/account/$ACCOUNT_ID/staking" \ - "${AUTH_HEADER[@]}")" -FT="$(curl -s "https://api.fastnear.com/v1/account/$ACCOUNT_ID/ft" \ - "${AUTH_HEADER[@]}")" +STAKING="$(curl -s "https://api.fastnear.com/v1/account/$ACCOUNT_ID/staking?apiKey=${FASTNEAR_API_KEY:-}")" +FT="$(curl -s "https://api.fastnear.com/v1/account/$ACCOUNT_ID/ft?apiKey=${FASTNEAR_API_KEY:-}")" jq -n \ --argjson staking "$STAKING" \ diff --git a/docs/fastdata/kv/examples.md b/docs/fastdata/kv/examples.md index 239d909..5a66388 100644 --- a/docs/fastdata/kv/examples.md +++ b/docs/fastdata/kv/examples.md @@ -10,7 +10,7 @@ page_actions: ## Examples -All shell examples below work on the public KV FastData hosts as-is. If `FASTNEAR_API_KEY` is set in your shell, they add it as a bearer header automatically; if it is unset, they fall back to the public unauthenticated path. +All shell examples below work on the public KV FastData hosts as-is. If `FASTNEAR_API_KEY` is set in your shell, they pass it as an `apiKey` query parameter automatically; if it is unset, they fall back to the public unauthenticated path. Bearer auth with `Authorization: Bearer ${FASTNEAR_API_KEY}` is also supported when headers fit your client better. ### Check one exact key, then replay its history @@ -20,13 +20,10 @@ When you already know the contract, predecessor, and exact key, start narrow. `l CURRENT_ACCOUNT_ID=social.near PREDECESSOR_ID=james.near KEY='graph/follow/sleet.near' -AUTH_HEADER=() -if [ -n "${FASTNEAR_API_KEY:-}" ]; then AUTH_HEADER=(-H "Authorization: Bearer $FASTNEAR_API_KEY"); fi ENCODED_KEY="$(jq -rn --arg key "$KEY" '$key | @uri')" -LATEST="$(curl -s "https://kv.main.fastnear.com/v0/latest/$CURRENT_ACCOUNT_ID/$PREDECESSOR_ID/$ENCODED_KEY" \ - "${AUTH_HEADER[@]}")" +LATEST="$(curl -s "https://kv.main.fastnear.com/v0/latest/$CURRENT_ACCOUNT_ID/$PREDECESSOR_ID/$ENCODED_KEY?apiKey=${FASTNEAR_API_KEY:-}")" echo "$LATEST" | jq '{ latest: ( @@ -41,8 +38,7 @@ echo "$LATEST" | jq '{ ) }' -curl -s "https://kv.main.fastnear.com/v0/history/$CURRENT_ACCOUNT_ID/$PREDECESSOR_ID/$ENCODED_KEY" \ - "${AUTH_HEADER[@]}" \ +curl -s "https://kv.main.fastnear.com/v0/history/$CURRENT_ACCOUNT_ID/$PREDECESSOR_ID/$ENCODED_KEY?apiKey=${FASTNEAR_API_KEY:-}" \ | jq '{writes: [.entries[] | {block_height, value}]}' ``` @@ -54,11 +50,8 @@ For an exact follow-edge style key like this, `latest` tells you the current ind ```bash PREDECESSOR_ID=jemartel.near -AUTH_HEADER=() -if [ -n "${FASTNEAR_API_KEY:-}" ]; then AUTH_HEADER=(-H "Authorization: Bearer $FASTNEAR_API_KEY"); fi -FIRST="$(curl -s "https://kv.main.fastnear.com/v0/all/$PREDECESSOR_ID" \ - "${AUTH_HEADER[@]}" \ +FIRST="$(curl -s "https://kv.main.fastnear.com/v0/all/$PREDECESSOR_ID?apiKey=${FASTNEAR_API_KEY:-}" \ -H 'content-type: application/json' \ --data '{"include_metadata":true,"limit":10}')" @@ -74,10 +67,7 @@ Lift the most recent row and replay it through `history`: ```bash PREDECESSOR_ID=jemartel.near -AUTH_HEADER=() -if [ -n "${FASTNEAR_API_KEY:-}" ]; then AUTH_HEADER=(-H "Authorization: Bearer $FASTNEAR_API_KEY"); fi -FIRST="$(curl -s "https://kv.main.fastnear.com/v0/all/$PREDECESSOR_ID" \ - "${AUTH_HEADER[@]}" \ +FIRST="$(curl -s "https://kv.main.fastnear.com/v0/all/$PREDECESSOR_ID?apiKey=${FASTNEAR_API_KEY:-}" \ -H 'content-type: application/json' \ --data '{"include_metadata":true,"limit":10}')" @@ -85,8 +75,7 @@ CURRENT_ACCOUNT_ID="$(echo "$FIRST" | jq -r '.entries[0].current_account_id')" EXACT_KEY="$(echo "$FIRST" | jq -r '.entries[0].key')" ENCODED_KEY="$(jq -rn --arg key "$EXACT_KEY" '$key | @uri')" -curl -s "https://kv.main.fastnear.com/v0/history/$CURRENT_ACCOUNT_ID/$PREDECESSOR_ID/$ENCODED_KEY" \ - "${AUTH_HEADER[@]}" \ +curl -s "https://kv.main.fastnear.com/v0/history/$CURRENT_ACCOUNT_ID/$PREDECESSOR_ID/$ENCODED_KEY?apiKey=${FASTNEAR_API_KEY:-}" \ | jq '{entries: [.entries[] | {block_height, value}]}' ``` diff --git a/docs/neardata/examples.md b/docs/neardata/examples.md index 4dd9a88..dba530c 100644 --- a/docs/neardata/examples.md +++ b/docs/neardata/examples.md @@ -12,18 +12,15 @@ page_actions: NEAR Data returns each block fully hydrated as one JSON document — header plus per-shard chunks, receipts, execution outcomes, and state changes — so a single `curl` gives you everything you need to filter for a specific contract without a second call. -All shell examples below work on the public NEAR Data hosts as-is. If `FASTNEAR_API_KEY` is set in your shell, they add it as a bearer header automatically; if it is unset, they fall back to the public unauthenticated path. +All shell examples below work on the public NEAR Data hosts as-is. If `FASTNEAR_API_KEY` is set in your shell, they pass it as an `apiKey` query parameter automatically; if it is unset, they fall back to the public unauthenticated path. Bearer auth with `Authorization: Bearer ${FASTNEAR_API_KEY}` is also supported when headers fit your client better. ### What block is NEAR on right now? `/v0/last_block/final` 302-redirects to the current finalized block. Before filtering for a specific contract, it's worth seeing what one block looks like at the protocol level: transactions arrive sharded, so the tx count for a block is a sum across shards — not a single top-level number. ```bash -AUTH_HEADER=() -if [ -n "${FASTNEAR_API_KEY:-}" ]; then AUTH_HEADER=(-H "Authorization: Bearer $FASTNEAR_API_KEY"); fi -curl -sL "https://mainnet.neardata.xyz/v0/last_block/final" \ - "${AUTH_HEADER[@]}" \ +curl -sL "https://mainnet.neardata.xyz/v0/last_block/final?apiKey=${FASTNEAR_API_KEY:-}" \ | jq '{ height: .block.header.height, timestamp_nanosec: .block.header.timestamp_nanosec, @@ -40,11 +37,8 @@ A live block shows 9 shards and a handful of transactions scattered across them ```bash TARGET_CONTRACT=intents.near -AUTH_HEADER=() -if [ -n "${FASTNEAR_API_KEY:-}" ]; then AUTH_HEADER=(-H "Authorization: Bearer $FASTNEAR_API_KEY"); fi -curl -sL "https://mainnet.neardata.xyz/v0/last_block/final" \ - "${AUTH_HEADER[@]}" \ +curl -sL "https://mainnet.neardata.xyz/v0/last_block/final?apiKey=${FASTNEAR_API_KEY:-}" \ | jq --arg contract "$TARGET_CONTRACT" '{ height: .block.header.height, contract: $contract, @@ -66,8 +60,6 @@ Optimistic blocks ship at `/v0/block_opt/{height}` about a second ahead of `/v0/ ```bash TARGET_CONTRACT=intents.near -AUTH_HEADER=() -if [ -n "${FASTNEAR_API_KEY:-}" ]; then AUTH_HEADER=(-H "Authorization: Bearer $FASTNEAR_API_KEY"); fi count_touches() { jq --arg contract "$1" ' @@ -78,15 +70,14 @@ count_touches() { } OPT_LOCATION="$( - curl -s -D - -o /dev/null "${AUTH_HEADER[@]}" "https://mainnet.neardata.xyz/v0/last_block/optimistic" \ + curl -s -D - -o /dev/null "https://mainnet.neardata.xyz/v0/last_block/optimistic?apiKey=${FASTNEAR_API_KEY:-}" \ | awk 'tolower($1) == "location:" {print $2}' | tr -d '\r' )" -OPT_HEIGHT="${OPT_LOCATION##*/}" +OPT_PATH="${OPT_LOCATION%%\?*}" +OPT_HEIGHT="${OPT_PATH##*/}" -echo "optimistic @ $OPT_HEIGHT: $(curl -s "https://mainnet.neardata.xyz$OPT_LOCATION" \ - "${AUTH_HEADER[@]}" | count_touches "$TARGET_CONTRACT") touches" -FINAL="$(curl -s "https://mainnet.neardata.xyz/v0/block/$OPT_HEIGHT" \ - "${AUTH_HEADER[@]}")" +echo "optimistic @ $OPT_HEIGHT: $(curl -s "https://mainnet.neardata.xyz$OPT_PATH?apiKey=${FASTNEAR_API_KEY:-}" | count_touches "$TARGET_CONTRACT") touches" +FINAL="$(curl -s "https://mainnet.neardata.xyz/v0/block/$OPT_HEIGHT?apiKey=${FASTNEAR_API_KEY:-}")" if [ "$(printf '%s' "$FINAL" | jq 'type')" = '"null"' ]; then echo "finalized @ $OPT_HEIGHT: not caught up yet" else @@ -102,18 +93,14 @@ Most finalized blocks show no state mutation for any given contract — activity ```bash TARGET_CONTRACT=intents.near -AUTH_HEADER=() -if [ -n "${FASTNEAR_API_KEY:-}" ]; then AUTH_HEADER=(-H "Authorization: Bearer $FASTNEAR_API_KEY"); fi -HEAD="$(curl -sL "https://mainnet.neardata.xyz/v0/last_block/final" \ - "${AUTH_HEADER[@]}" | jq '.block.header.height')" +HEAD="$(curl -sL "https://mainnet.neardata.xyz/v0/last_block/final?apiKey=${FASTNEAR_API_KEY:-}" | jq '.block.header.height')" FOUND_HEIGHT="" FOUND_SHARD="" for OFFSET in $(seq 0 15); do H=$((HEAD - OFFSET)) - SHARD="$(curl -s "https://mainnet.neardata.xyz/v0/block/$H" \ - "${AUTH_HEADER[@]}" \ + SHARD="$(curl -s "https://mainnet.neardata.xyz/v0/block/$H?apiKey=${FASTNEAR_API_KEY:-}" \ | jq -r --arg contract "$TARGET_CONTRACT" ' .shards[] | select([.state_changes[]? | select(.change.account_id? == $contract)] | length > 0) @@ -128,8 +115,7 @@ done if [ -z "$FOUND_HEIGHT" ]; then echo "no state mutation for $TARGET_CONTRACT in the last 16 finalized blocks" else - curl -s "https://mainnet.neardata.xyz/v0/block/$FOUND_HEIGHT/shard/$FOUND_SHARD" \ - "${AUTH_HEADER[@]}" \ + curl -s "https://mainnet.neardata.xyz/v0/block/$FOUND_HEIGHT/shard/$FOUND_SHARD?apiKey=${FASTNEAR_API_KEY:-}" \ | jq --arg contract "$TARGET_CONTRACT" --argjson height "$FOUND_HEIGHT" --argjson shard_id "$FOUND_SHARD" '{ height: $height, shard_id: $shard_id, diff --git a/docs/rpc/examples.md b/docs/rpc/examples.md index 3bd401f..7bd0ba1 100644 --- a/docs/rpc/examples.md +++ b/docs/rpc/examples.md @@ -12,7 +12,7 @@ page_actions: Start with the RPC method that answers the question. Use `tx` to track inclusion and finality from a tx hash, and widen only when you need receipt trees, raw state, or shard-level tracing. -All shell examples below work on the public RPC hosts as-is. If `FASTNEAR_API_KEY` is set in your shell, they add it as a bearer header automatically; if it is unset, they fall back to the public unauthenticated path. +All shell examples below work on the public RPC hosts as-is. If `FASTNEAR_API_KEY` is set in your shell, they pass it as an `apiKey` query parameter automatically; if it is unset, they fall back to the public unauthenticated path. Bearer auth with `Authorization: Bearer ${FASTNEAR_API_KEY}` is also supported when headers fit your client better. ## Account State @@ -22,11 +22,8 @@ All shell examples below work on the public RPC hosts as-is. If `FASTNEAR_API_KE ```bash ACCOUNT_ID=root.near -AUTH_HEADER=() -if [ -n "${FASTNEAR_API_KEY:-}" ]; then AUTH_HEADER=(-H "Authorization: Bearer $FASTNEAR_API_KEY"); fi -curl -s "https://rpc.mainnet.fastnear.com" \ - "${AUTH_HEADER[@]}" \ +curl -s "https://rpc.mainnet.fastnear.com?apiKey=${FASTNEAR_API_KEY:-}" \ -H 'content-type: application/json' \ --data "$(jq -nc --arg account_id "$ACCOUNT_ID" '{ jsonrpc:"2.0",id:"fastnear",method:"query", @@ -46,11 +43,8 @@ Have a tx hash? Poll `tx` with the smallest `wait_until` threshold that answers ```bash TX_HASH=CVyG2xLJ6fuKCtULAxMnWTh2GL5ey2UUiTcgYT3M6Pow SIGNER_ACCOUNT_ID=mike.testnet -AUTH_HEADER=() -if [ -n "${FASTNEAR_API_KEY:-}" ]; then AUTH_HEADER=(-H "Authorization: Bearer $FASTNEAR_API_KEY"); fi -curl -s "https://archival-rpc.testnet.fastnear.com" \ - "${AUTH_HEADER[@]}" \ +curl -s "https://archival-rpc.testnet.fastnear.com?apiKey=${FASTNEAR_API_KEY:-}" \ -H 'content-type: application/json' \ --data "$(jq -nc --arg tx_hash "$TX_HASH" --arg signer_id "$SIGNER_ACCOUNT_ID" '{ jsonrpc: "2.0", id: "fastnear", method: "tx", @@ -79,14 +73,12 @@ A NEAR block is a header over N shard chunks, not a flat list of transactions. ` ```bash EMPTY_TX_ROOT=11111111111111111111111111111111 -AUTH_HEADER=() -if [ -n "${FASTNEAR_API_KEY:-}" ]; then AUTH_HEADER=(-H "Authorization: Bearer $FASTNEAR_API_KEY"); fi -BLOCK_HASH="$(curl -s "https://rpc.mainnet.fastnear.com" "${AUTH_HEADER[@]}" -H 'content-type: application/json' \ +BLOCK_HASH="$(curl -s "https://rpc.mainnet.fastnear.com?apiKey=${FASTNEAR_API_KEY:-}" -H 'content-type: application/json' \ --data '{"jsonrpc":"2.0","id":"fastnear","method":"status","params":[]}' \ | jq -r '.result.sync_info.latest_block_hash')" -CHUNK_HASH="$(curl -s "https://rpc.mainnet.fastnear.com" "${AUTH_HEADER[@]}" -H 'content-type: application/json' \ +CHUNK_HASH="$(curl -s "https://rpc.mainnet.fastnear.com?apiKey=${FASTNEAR_API_KEY:-}" -H 'content-type: application/json' \ --data "$(jq -nc --arg block_hash "$BLOCK_HASH" '{ jsonrpc:"2.0",id:"fastnear",method:"block",params:{block_id:$block_hash} }')" \ @@ -96,7 +88,7 @@ CHUNK_HASH="$(curl -s "https://rpc.mainnet.fastnear.com" "${AUTH_HEADER[@]}" -H if [ -z "$CHUNK_HASH" ]; then echo "tip block had no transactions in any chunk — rerun on the next head" else - curl -s "https://rpc.mainnet.fastnear.com" "${AUTH_HEADER[@]}" -H 'content-type: application/json' \ + curl -s "https://rpc.mainnet.fastnear.com?apiKey=${FASTNEAR_API_KEY:-}" -H 'content-type: application/json' \ --data "$(jq -nc --arg chunk_hash "$CHUNK_HASH" '{ jsonrpc:"2.0",id:"fastnear",method:"chunk",params:{chunk_id:$chunk_hash} }')" \ @@ -136,11 +128,8 @@ Any key with `tx_count: 0` was created and never used — the clearest candidate ```bash ACCOUNT_ID=root.near RECEIVER_ID=social.near -AUTH_HEADER=() -if [ -n "${FASTNEAR_API_KEY:-}" ]; then AUTH_HEADER=(-H "Authorization: Bearer $FASTNEAR_API_KEY"); fi -curl -s "https://rpc.mainnet.fastnear.com" \ - "${AUTH_HEADER[@]}" \ +curl -s "https://rpc.mainnet.fastnear.com?apiKey=${FASTNEAR_API_KEY:-}" \ -H 'content-type: application/json' \ --data "$(jq -nc --arg account_id "$ACCOUNT_ID" '{ jsonrpc:"2.0",id:"fastnear",method:"query", @@ -178,10 +167,8 @@ Contracts built with `near-sdk-rs` store the top-level `#[near_bindgen]` struct ```bash CONTRACT_ID=counter.near-examples.testnet -AUTH_HEADER=() -if [ -n "${FASTNEAR_API_KEY:-}" ]; then AUTH_HEADER=(-H "Authorization: Bearer $FASTNEAR_API_KEY"); fi -RAW_B64="$(curl -s "https://rpc.testnet.fastnear.com" "${AUTH_HEADER[@]}" -H 'content-type: application/json' \ +RAW_B64="$(curl -s "https://rpc.testnet.fastnear.com?apiKey=${FASTNEAR_API_KEY:-}" -H 'content-type: application/json' \ --data "$(jq -nc --arg contract "$CONTRACT_ID" '{ jsonrpc:"2.0",id:"fastnear",method:"query", params:{request_type:"view_state",account_id:$contract,prefix_base64:"U1RBVEU=",finality:"final"} @@ -208,12 +195,10 @@ These stay on exact SocialDB reads and on-chain readiness checks until the quest ```bash ACCOUNT_ID=root.near # account you're writing under SIGNER_ACCOUNT_ID=root.near # account signing the transaction -AUTH_HEADER=() -if [ -n "${FASTNEAR_API_KEY:-}" ]; then AUTH_HEADER=(-H "Authorization: Bearer $FASTNEAR_API_KEY"); fi STORAGE_ARGS_B64="$(jq -nc --arg account_id "$ACCOUNT_ID" '{account_id:$account_id}' | base64 | tr -d '\n')" -STORAGE="$(curl -s "https://rpc.mainnet.fastnear.com" "${AUTH_HEADER[@]}" -H 'content-type: application/json' \ +STORAGE="$(curl -s "https://rpc.mainnet.fastnear.com?apiKey=${FASTNEAR_API_KEY:-}" -H 'content-type: application/json' \ --data "$(jq -nc --arg args "$STORAGE_ARGS_B64" '{ jsonrpc:"2.0",id:"fastnear",method:"query", params:{request_type:"call_function",account_id:"social.near",method_name:"get_account_storage",args_base64:$args,finality:"final"} @@ -224,7 +209,7 @@ if [ "$SIGNER_ACCOUNT_ID" = "$ACCOUNT_ID" ]; then PERMISSION=true else PERM_ARGS_B64="$(jq -nc --arg pred "$SIGNER_ACCOUNT_ID" --arg key "$ACCOUNT_ID" '{predecessor_id:$pred,key:$key}' | base64 | tr -d '\n')" - PERMISSION="$(curl -s "https://rpc.mainnet.fastnear.com" "${AUTH_HEADER[@]}" -H 'content-type: application/json' \ + PERMISSION="$(curl -s "https://rpc.mainnet.fastnear.com?apiKey=${FASTNEAR_API_KEY:-}" -H 'content-type: application/json' \ --data "$(jq -nc --arg args "$PERM_ARGS_B64" '{ jsonrpc:"2.0",id:"fastnear",method:"query", params:{request_type:"call_function",account_id:"social.near",method_name:"is_write_permission_granted",args_base64:$args,finality:"final"} @@ -251,15 +236,13 @@ SocialDB stores BOS widgets as `/widget/` keys on `social.near`. ```bash ACCOUNT_ID=mob.near WIDGET_NAME=Profile -AUTH_HEADER=() -if [ -n "${FASTNEAR_API_KEY:-}" ]; then AUTH_HEADER=(-H "Authorization: Bearer $FASTNEAR_API_KEY"); fi KEYS_ARGS="$(jq -nc --arg account_id "$ACCOUNT_ID" '{ keys: [($account_id + "/widget/*")], options: {return_type: "BlockHeight"} }' | base64 | tr -d '\n')" -curl -s "https://rpc.mainnet.fastnear.com" "${AUTH_HEADER[@]}" -H 'content-type: application/json' \ +curl -s "https://rpc.mainnet.fastnear.com?apiKey=${FASTNEAR_API_KEY:-}" -H 'content-type: application/json' \ --data "$(jq -nc --arg args "$KEYS_ARGS" '{ jsonrpc:"2.0",id:"fastnear",method:"query", params:{request_type:"call_function",account_id:"social.near",method_name:"keys",args_base64:$args,finality:"final"} @@ -276,7 +259,7 @@ GET_ARGS="$(jq -nc --arg account_id "$ACCOUNT_ID" --arg widget "$WIDGET_NAME" '{ keys: [($account_id + "/widget/" + $widget)] }' | base64 | tr -d '\n')" -curl -s "https://rpc.mainnet.fastnear.com" "${AUTH_HEADER[@]}" -H 'content-type: application/json' \ +curl -s "https://rpc.mainnet.fastnear.com?apiKey=${FASTNEAR_API_KEY:-}" -H 'content-type: application/json' \ --data "$(jq -nc --arg args "$GET_ARGS" '{ jsonrpc:"2.0",id:"fastnear",method:"query", params:{request_type:"call_function",account_id:"social.near",method_name:"get",args_base64:$args,finality:"final"} diff --git a/docs/transfers/examples.md b/docs/transfers/examples.md index b0235a1..ca3a8a6 100644 --- a/docs/transfers/examples.md +++ b/docs/transfers/examples.md @@ -10,7 +10,7 @@ page_actions: ## Examples -These shell examples work on the public Transfers and Transactions endpoints. If `FASTNEAR_API_KEY` is already set in your shell, the snippets forward it as a bearer header automatically. +These shell examples work on the public Transfers and Transactions endpoints. If `FASTNEAR_API_KEY` is set in your shell, the snippets pass it as an `apiKey` query parameter automatically; if it is unset, they fall back to the public unauthenticated path. Bearer auth with `Authorization: Bearer ${FASTNEAR_API_KEY}` is also supported when headers fit your client better. ### What's this account's recent transfer activity? @@ -18,11 +18,8 @@ These shell examples work on the public Transfers and Transactions endpoints. If ```bash ACCOUNT_ID=root.near -AUTH_HEADER=() -if [ -n "${FASTNEAR_API_KEY:-}" ]; then AUTH_HEADER=(-H "Authorization: Bearer $FASTNEAR_API_KEY"); fi -curl -s "https://transfers.main.fastnear.com/v0/transfers" \ - "${AUTH_HEADER[@]}" \ +curl -s "https://transfers.main.fastnear.com/v0/transfers?apiKey=${FASTNEAR_API_KEY:-}" \ -H 'content-type: application/json' \ --data "$(jq -nc --arg account_id "$ACCOUNT_ID" '{account_id: $account_id, desc: true, limit: 5}')" \ | jq '{ @@ -45,11 +42,8 @@ For `root.near`, the latest rows mix `FtTransfer` and `MtTransfer` assets. `asse ```bash ACCOUNT_ID=root.near -AUTH_HEADER=() -if [ -n "${FASTNEAR_API_KEY:-}" ]; then AUTH_HEADER=(-H "Authorization: Bearer $FASTNEAR_API_KEY"); fi -FEED="$(curl -s "https://transfers.main.fastnear.com/v0/transfers" \ - "${AUTH_HEADER[@]}" \ +FEED="$(curl -s "https://transfers.main.fastnear.com/v0/transfers?apiKey=${FASTNEAR_API_KEY:-}" \ -H 'content-type: application/json' \ --data "$(jq -nc --arg account_id "$ACCOUNT_ID" '{ account_id: $account_id, @@ -72,10 +66,7 @@ When one row needs its execution anchor, take its `receipt_id` straight to `/v0/ ```bash ACCOUNT_ID=root.near -AUTH_HEADER=() -if [ -n "${FASTNEAR_API_KEY:-}" ]; then AUTH_HEADER=(-H "Authorization: Bearer $FASTNEAR_API_KEY"); fi -FEED="$(curl -s "https://transfers.main.fastnear.com/v0/transfers" \ - "${AUTH_HEADER[@]}" \ +FEED="$(curl -s "https://transfers.main.fastnear.com/v0/transfers?apiKey=${FASTNEAR_API_KEY:-}" \ -H 'content-type: application/json' \ --data "$(jq -nc --arg account_id "$ACCOUNT_ID" '{ account_id: $account_id, @@ -87,8 +78,7 @@ FEED="$(curl -s "https://transfers.main.fastnear.com/v0/transfers" \ }')")" RECEIPT_ID="$(echo "$FEED" | jq -r '.transfers[0].receipt_id')" -curl -s "https://tx.main.fastnear.com/v0/receipt" \ - "${AUTH_HEADER[@]}" \ +curl -s "https://tx.main.fastnear.com/v0/receipt?apiKey=${FASTNEAR_API_KEY:-}" \ -H 'content-type: application/json' \ --data "$(jq -nc --arg receipt_id "$RECEIPT_ID" '{receipt_id: $receipt_id}')" \ | jq '.receipt | {receipt_id, transaction_hash, receiver_id, predecessor_id, tx_block_height, is_success}' diff --git a/docs/tx/examples.md b/docs/tx/examples.md index e7be78b..6dc3866 100644 --- a/docs/tx/examples.md +++ b/docs/tx/examples.md @@ -10,7 +10,7 @@ page_actions: ## Start Here -All shell examples below work on the public Transactions API hosts as-is. If `FASTNEAR_API_KEY` is set in your shell, they add it as a bearer header automatically; if it is unset, they fall back to the public unauthenticated path. +All shell examples below work on the public Transactions API hosts as-is. If `FASTNEAR_API_KEY` is set in your shell, they pass it as an `apiKey` query parameter automatically; if it is unset, they fall back to the public unauthenticated path. Bearer auth with `Authorization: Bearer ${FASTNEAR_API_KEY}` is also supported when headers fit your client better. ### I have one transaction hash. What happened? @@ -18,11 +18,8 @@ Paste the hash into `POST /v0/transactions` and one response usually holds the w ```bash TX_HASH=7ZKnhzt2MqMNmsk13dV8GAjGu3Db8aHzSBHeNeu9MJCq -AUTH_HEADER=() -if [ -n "${FASTNEAR_API_KEY:-}" ]; then AUTH_HEADER=(-H "Authorization: Bearer $FASTNEAR_API_KEY"); fi -curl -s "https://tx.main.fastnear.com/v0/transactions" \ - "${AUTH_HEADER[@]}" \ +curl -s "https://tx.main.fastnear.com/v0/transactions?apiKey=${FASTNEAR_API_KEY:-}" \ -H 'content-type: application/json' \ --data "$(jq -nc --arg tx_hash "$TX_HASH" '{tx_hashes: [$tx_hash]}')" \ | jq '{ @@ -45,11 +42,8 @@ List every logged receipt in the transaction with a flag for whether its logs co ```bash TX_HASH=2KhhB1uDScGCFQfVchep7DiZTGTxMcgfUYHNzwf5e6uL LOG_FRAGMENT=Refund -AUTH_HEADER=() -if [ -n "${FASTNEAR_API_KEY:-}" ]; then AUTH_HEADER=(-H "Authorization: Bearer $FASTNEAR_API_KEY"); fi -curl -s "https://tx.main.fastnear.com/v0/transactions" \ - "${AUTH_HEADER[@]}" \ +curl -s "https://tx.main.fastnear.com/v0/transactions?apiKey=${FASTNEAR_API_KEY:-}" \ -H 'content-type: application/json' \ --data "$(jq -nc --arg tx_hash "$TX_HASH" '{tx_hashes: [$tx_hash]}')" \ | jq --arg fragment "$LOG_FRAGMENT" ' @@ -75,11 +69,8 @@ The `Refund` fragment attributes to receipt `9sLHQpaGz3NnMNMn8zGrDUSyktR1q6ts2ot ```bash RECEIPT_ID=B8QzHQZ6VnUVy8zaVXCEkWuSs7MPb34yoHYixZV3Zdj1 -AUTH_HEADER=() -if [ -n "${FASTNEAR_API_KEY:-}" ]; then AUTH_HEADER=(-H "Authorization: Bearer $FASTNEAR_API_KEY"); fi -curl -s "https://tx.main.fastnear.com/v0/receipt" \ - "${AUTH_HEADER[@]}" \ +curl -s "https://tx.main.fastnear.com/v0/receipt?apiKey=${FASTNEAR_API_KEY:-}" \ -H 'content-type: application/json' \ --data "$(jq -nc --arg receipt_id "$RECEIPT_ID" '{receipt_id: $receipt_id}')" \ | jq '{ @@ -112,11 +103,8 @@ One batch submitted `CreateAccount → Transfer → AddKey → FunctionCall` and ```bash TX_HASH=CrhH3xLzbNwNMGgZkgptXorwh8YmqxRGuA6Mc11MkU6M NEW_ACCOUNT_ID=rollback-mo4vmkig.temp.mike.testnet -AUTH_HEADER=() -if [ -n "${FASTNEAR_API_KEY:-}" ]; then AUTH_HEADER=(-H "Authorization: Bearer $FASTNEAR_API_KEY"); fi -curl -s "https://tx.test.fastnear.com/v0/transactions" \ - "${AUTH_HEADER[@]}" \ +curl -s "https://tx.test.fastnear.com/v0/transactions?apiKey=${FASTNEAR_API_KEY:-}" \ -H 'content-type: application/json' \ --data "$(jq -nc --arg tx_hash "$TX_HASH" '{tx_hashes: [$tx_hash]}')" \ | jq '{ @@ -139,11 +127,8 @@ Now prove the earlier actions rolled back by asking for the account the batch *t ```bash NEW_ACCOUNT_ID=rollback-mo4vmkig.temp.mike.testnet -AUTH_HEADER=() -if [ -n "${FASTNEAR_API_KEY:-}" ]; then AUTH_HEADER=(-H "Authorization: Bearer $FASTNEAR_API_KEY"); fi -curl -s "https://rpc.testnet.fastnear.com" \ - "${AUTH_HEADER[@]}" \ +curl -s "https://rpc.testnet.fastnear.com?apiKey=${FASTNEAR_API_KEY:-}" \ -H 'content-type: application/json' \ --data "$(jq -nc --arg account_id "$NEW_ACCOUNT_ID" '{ jsonrpc: "2.0", id: "fastnear", method: "query", @@ -162,11 +147,8 @@ A tx's outer `execution_outcome.outcome.status` reports `SuccessReceiptId` whene TX_HASH=2KhhB1uDScGCFQfVchep7DiZTGTxMcgfUYHNzwf5e6uL ORIGIN_CONTRACT_ID=wrap.near CALLBACK_METHOD=ft_resolve_transfer -AUTH_HEADER=() -if [ -n "${FASTNEAR_API_KEY:-}" ]; then AUTH_HEADER=(-H "Authorization: Bearer $FASTNEAR_API_KEY"); fi -curl -s "https://tx.main.fastnear.com/v0/transactions" \ - "${AUTH_HEADER[@]}" \ +curl -s "https://tx.main.fastnear.com/v0/transactions?apiKey=${FASTNEAR_API_KEY:-}" \ -H 'content-type: application/json' \ --data "$(jq -nc --arg tx_hash "$TX_HASH" '{tx_hashes: [$tx_hash]}')" \ | jq --arg origin "$ORIGIN_CONTRACT_ID" --arg callback "$CALLBACK_METHOD" '{ @@ -206,11 +188,8 @@ Receipt success is not transitive. A protocol can hand off cleanly and still see ```bash REQUEST_TX=BZDQAxEdpQ9wUGXmXTa2APwFLDTTqTy5ucrBPsfgZeyz WORKER_TX=3NYD4Mkn5cwkuVkGP9PPoiJ9PB5Vr7v6r8CwSswtHVA3 -AUTH_HEADER=() -if [ -n "${FASTNEAR_API_KEY:-}" ]; then AUTH_HEADER=(-H "Authorization: Bearer $FASTNEAR_API_KEY"); fi -curl -s "https://tx.main.fastnear.com/v0/transactions" \ - "${AUTH_HEADER[@]}" \ +curl -s "https://tx.main.fastnear.com/v0/transactions?apiKey=${FASTNEAR_API_KEY:-}" \ -H 'content-type: application/json' \ --data "$(jq -nc --arg a "$REQUEST_TX" --arg b "$WORKER_TX" '{tx_hashes: [$a, $b]}')" \ | jq '[ diff --git a/i18n/ru/docusaurus-plugin-content-docs/current/api/examples.md b/i18n/ru/docusaurus-plugin-content-docs/current/api/examples.md index 6868726..5f22dc8 100644 --- a/i18n/ru/docusaurus-plugin-content-docs/current/api/examples.md +++ b/i18n/ru/docusaurus-plugin-content-docs/current/api/examples.md @@ -10,7 +10,7 @@ page_actions: ## Примеры -Все shell-примеры ниже работают на публичных FastNear API-хостах как есть. Если в shell задан `FASTNEAR_API_KEY`, они автоматически добавляют bearer header; если переменная не задана, они переходят на публичный неаутентифицированный путь. +Все shell-примеры ниже работают на публичных FastNear API-хостах как есть. Если в shell задан `FASTNEAR_API_KEY`, они автоматически передают его как query-параметр `apiKey`; если переменная не задана, они переходят на публичный неаутентифицированный путь. Также поддерживается bearer-аутентификация через `Authorization: Bearer ${FASTNEAR_API_KEY}`, если вашему клиенту удобнее передавать ключ в заголовке. ### Свести один аккаунт за один вызов @@ -18,11 +18,8 @@ page_actions: ```bash ACCOUNT_ID=root.near -AUTH_HEADER=() -if [ -n "${FASTNEAR_API_KEY:-}" ]; then AUTH_HEADER=(-H "Authorization: Bearer $FASTNEAR_API_KEY"); fi -curl -s "https://api.fastnear.com/v1/account/$ACCOUNT_ID/full" \ - "${AUTH_HEADER[@]}" \ +curl -s "https://api.fastnear.com/v1/account/$ACCOUNT_ID/full?apiKey=${FASTNEAR_API_KEY:-}" \ | jq '{ account_id, near_balance_yocto: .state.balance, @@ -40,18 +37,14 @@ curl -s "https://api.fastnear.com/v1/account/$ACCOUNT_ID/full" \ ```bash PUBLIC_KEY='ed25519:CCaThr3uokqnUs6Z5vVnaDcJdrfuTpYJHJWcAGubDjT' -AUTH_HEADER=() -if [ -n "${FASTNEAR_API_KEY:-}" ]; then AUTH_HEADER=(-H "Authorization: Bearer $FASTNEAR_API_KEY"); fi -LOOKUP="$(curl -s "https://api.fastnear.com/v1/public_key/$(jq -rn --arg k "$PUBLIC_KEY" '$k | @uri')" \ - "${AUTH_HEADER[@]}")" +LOOKUP="$(curl -s "https://api.fastnear.com/v1/public_key/$(jq -rn --arg k "$PUBLIC_KEY" '$k | @uri')?apiKey=${FASTNEAR_API_KEY:-}")" echo "$LOOKUP" | jq '{matched: (.account_ids | length), account_ids}' ACCOUNT_ID="$(echo "$LOOKUP" | jq -r '.account_ids[0]')" -curl -s "https://api.fastnear.com/v1/account/$ACCOUNT_ID/full" \ - "${AUTH_HEADER[@]}" \ +curl -s "https://api.fastnear.com/v1/account/$ACCOUNT_ID/full?apiKey=${FASTNEAR_API_KEY:-}" \ | jq '{account_id, state, tokens: (.tokens|length), nfts: (.nfts|length), pools: (.pools|length)}' ``` @@ -63,11 +56,8 @@ curl -s "https://api.fastnear.com/v1/account/$ACCOUNT_ID/full" \ ```bash ACCOUNT_ID=root.near -AUTH_HEADER=() -if [ -n "${FASTNEAR_API_KEY:-}" ]; then AUTH_HEADER=(-H "Authorization: Bearer $FASTNEAR_API_KEY"); fi -curl -s "https://api.fastnear.com/v1/account/$ACCOUNT_ID/full" \ - "${AUTH_HEADER[@]}" \ +curl -s "https://api.fastnear.com/v1/account/$ACCOUNT_ID/full?apiKey=${FASTNEAR_API_KEY:-}" \ | jq ' (.state.balance | tonumber) as $amount | (.state.locked | tonumber) as $locked @@ -97,11 +87,8 @@ jq считает в IEEE-754 double, поэтому NEAR-значения вы ```bash ACCOUNT_ID=root.near -AUTH_HEADER=() -if [ -n "${FASTNEAR_API_KEY:-}" ]; then AUTH_HEADER=(-H "Authorization: Bearer $FASTNEAR_API_KEY"); fi -curl -s "https://api.fastnear.com/v1/account/$ACCOUNT_ID/full" \ - "${AUTH_HEADER[@]}" \ +curl -s "https://api.fastnear.com/v1/account/$ACCOUNT_ID/full?apiKey=${FASTNEAR_API_KEY:-}" \ | jq ' [ (.tokens // [])[].last_update_block_height, @@ -129,11 +116,8 @@ curl -s "https://api.fastnear.com/v1/account/$ACCOUNT_ID/full" \ ```bash ACCOUNT_ID=root.near PUBLISHER=sharddog.near -AUTH_HEADER=() -if [ -n "${FASTNEAR_API_KEY:-}" ]; then AUTH_HEADER=(-H "Authorization: Bearer $FASTNEAR_API_KEY"); fi -curl -s "https://api.fastnear.com/v1/account/$ACCOUNT_ID/nft" \ - "${AUTH_HEADER[@]}" \ +curl -s "https://api.fastnear.com/v1/account/$ACCOUNT_ID/nft?apiKey=${FASTNEAR_API_KEY:-}" \ | jq --arg publisher "$PUBLISHER" ' ("." + $publisher) as $suffix | { @@ -162,13 +146,9 @@ curl -s "https://api.fastnear.com/v1/account/$ACCOUNT_ID/nft" \ ```bash ACCOUNT_ID=root.near LIQUID_PROVIDERS_JSON='["meta-pool.near","lst.rhealab.near","linear-protocol.near"]' -AUTH_HEADER=() -if [ -n "${FASTNEAR_API_KEY:-}" ]; then AUTH_HEADER=(-H "Authorization: Bearer $FASTNEAR_API_KEY"); fi -STAKING="$(curl -s "https://api.fastnear.com/v1/account/$ACCOUNT_ID/staking" \ - "${AUTH_HEADER[@]}")" -FT="$(curl -s "https://api.fastnear.com/v1/account/$ACCOUNT_ID/ft" \ - "${AUTH_HEADER[@]}")" +STAKING="$(curl -s "https://api.fastnear.com/v1/account/$ACCOUNT_ID/staking?apiKey=${FASTNEAR_API_KEY:-}")" +FT="$(curl -s "https://api.fastnear.com/v1/account/$ACCOUNT_ID/ft?apiKey=${FASTNEAR_API_KEY:-}")" jq -n \ --argjson staking "$STAKING" \ diff --git a/i18n/ru/docusaurus-plugin-content-docs/current/fastdata/kv/examples.md b/i18n/ru/docusaurus-plugin-content-docs/current/fastdata/kv/examples.md index 4656e25..3df4a9e 100644 --- a/i18n/ru/docusaurus-plugin-content-docs/current/fastdata/kv/examples.md +++ b/i18n/ru/docusaurus-plugin-content-docs/current/fastdata/kv/examples.md @@ -10,7 +10,7 @@ page_actions: ## Примеры -Все shell-примеры ниже работают на публичных KV FastData-хостах как есть. Если в shell задан `FASTNEAR_API_KEY`, они автоматически добавляют bearer header; если переменная не задана, они переходят на публичный неаутентифицированный путь. +Все shell-примеры ниже работают на публичных KV FastData-хостах как есть. Если в shell задан `FASTNEAR_API_KEY`, они автоматически передают его как query-параметр `apiKey`; если переменная не задана, они переходят на публичный неаутентифицированный путь. Также поддерживается bearer-аутентификация через `Authorization: Bearer ${FASTNEAR_API_KEY}`, если вашему клиенту удобнее передавать ключ в заголовке. ### Проверить один точный ключ и сразу посмотреть его историю @@ -20,13 +20,10 @@ page_actions: CURRENT_ACCOUNT_ID=social.near PREDECESSOR_ID=james.near KEY='graph/follow/sleet.near' -AUTH_HEADER=() -if [ -n "${FASTNEAR_API_KEY:-}" ]; then AUTH_HEADER=(-H "Authorization: Bearer $FASTNEAR_API_KEY"); fi ENCODED_KEY="$(jq -rn --arg key "$KEY" '$key | @uri')" -LATEST="$(curl -s "https://kv.main.fastnear.com/v0/latest/$CURRENT_ACCOUNT_ID/$PREDECESSOR_ID/$ENCODED_KEY" \ - "${AUTH_HEADER[@]}")" +LATEST="$(curl -s "https://kv.main.fastnear.com/v0/latest/$CURRENT_ACCOUNT_ID/$PREDECESSOR_ID/$ENCODED_KEY?apiKey=${FASTNEAR_API_KEY:-}")" echo "$LATEST" | jq '{ latest: ( @@ -41,8 +38,7 @@ echo "$LATEST" | jq '{ ) }' -curl -s "https://kv.main.fastnear.com/v0/history/$CURRENT_ACCOUNT_ID/$PREDECESSOR_ID/$ENCODED_KEY" \ - "${AUTH_HEADER[@]}" \ +curl -s "https://kv.main.fastnear.com/v0/history/$CURRENT_ACCOUNT_ID/$PREDECESSOR_ID/$ENCODED_KEY?apiKey=${FASTNEAR_API_KEY:-}" \ | jq '{writes: [.entries[] | {block_height, value}]}' ``` @@ -54,11 +50,8 @@ curl -s "https://kv.main.fastnear.com/v0/history/$CURRENT_ACCOUNT_ID/$PREDECESSO ```bash PREDECESSOR_ID=jemartel.near -AUTH_HEADER=() -if [ -n "${FASTNEAR_API_KEY:-}" ]; then AUTH_HEADER=(-H "Authorization: Bearer $FASTNEAR_API_KEY"); fi -FIRST="$(curl -s "https://kv.main.fastnear.com/v0/all/$PREDECESSOR_ID" \ - "${AUTH_HEADER[@]}" \ +FIRST="$(curl -s "https://kv.main.fastnear.com/v0/all/$PREDECESSOR_ID?apiKey=${FASTNEAR_API_KEY:-}" \ -H 'content-type: application/json' \ --data '{"include_metadata":true,"limit":10}')" @@ -74,10 +67,7 @@ echo "$FIRST" | jq '{ ```bash PREDECESSOR_ID=jemartel.near -AUTH_HEADER=() -if [ -n "${FASTNEAR_API_KEY:-}" ]; then AUTH_HEADER=(-H "Authorization: Bearer $FASTNEAR_API_KEY"); fi -FIRST="$(curl -s "https://kv.main.fastnear.com/v0/all/$PREDECESSOR_ID" \ - "${AUTH_HEADER[@]}" \ +FIRST="$(curl -s "https://kv.main.fastnear.com/v0/all/$PREDECESSOR_ID?apiKey=${FASTNEAR_API_KEY:-}" \ -H 'content-type: application/json' \ --data '{"include_metadata":true,"limit":10}')" @@ -85,8 +75,7 @@ CURRENT_ACCOUNT_ID="$(echo "$FIRST" | jq -r '.entries[0].current_account_id')" EXACT_KEY="$(echo "$FIRST" | jq -r '.entries[0].key')" ENCODED_KEY="$(jq -rn --arg key "$EXACT_KEY" '$key | @uri')" -curl -s "https://kv.main.fastnear.com/v0/history/$CURRENT_ACCOUNT_ID/$PREDECESSOR_ID/$ENCODED_KEY" \ - "${AUTH_HEADER[@]}" \ +curl -s "https://kv.main.fastnear.com/v0/history/$CURRENT_ACCOUNT_ID/$PREDECESSOR_ID/$ENCODED_KEY?apiKey=${FASTNEAR_API_KEY:-}" \ | jq '{entries: [.entries[] | {block_height, value}]}' ``` diff --git a/i18n/ru/docusaurus-plugin-content-docs/current/neardata/examples.md b/i18n/ru/docusaurus-plugin-content-docs/current/neardata/examples.md index b371522..e8ceae9 100644 --- a/i18n/ru/docusaurus-plugin-content-docs/current/neardata/examples.md +++ b/i18n/ru/docusaurus-plugin-content-docs/current/neardata/examples.md @@ -12,18 +12,15 @@ page_actions: NEAR Data возвращает каждый блок полностью гидратированным одним JSON-документом — header плюс per-shard chunks, receipts, результаты исполнения и state changes, — так что один `curl` уже даёт всё необходимое, чтобы отфильтровать нужный контракт без второго запроса. -Все shell-примеры ниже работают на публичных NEAR Data-хостах как есть. Если в shell задан `FASTNEAR_API_KEY`, они автоматически добавляют bearer header; если переменная не задана, они переходят на публичный неаутентифицированный путь. +Все shell-примеры ниже работают на публичных NEAR Data-хостах как есть. Если в shell задан `FASTNEAR_API_KEY`, они автоматически передают его как query-параметр `apiKey`; если переменная не задана, они переходят на публичный неаутентифицированный путь. Также поддерживается bearer-аутентификация через `Authorization: Bearer ${FASTNEAR_API_KEY}`, если вашему клиенту удобнее передавать ключ в заголовке. ### На каком блоке NEAR сейчас? `/v0/last_block/final` отдаёт 302-редирект на текущий финализированный блок. Прежде чем фильтровать по конкретному контракту, полезно увидеть, как выглядит один блок на уровне протокола: транзакции приходят с разбивкой по shard, поэтому общее число транзакций в блоке — это сумма по shards, а не одно поле верхнего уровня. ```bash -AUTH_HEADER=() -if [ -n "${FASTNEAR_API_KEY:-}" ]; then AUTH_HEADER=(-H "Authorization: Bearer $FASTNEAR_API_KEY"); fi -curl -sL "https://mainnet.neardata.xyz/v0/last_block/final" \ - "${AUTH_HEADER[@]}" \ +curl -sL "https://mainnet.neardata.xyz/v0/last_block/final?apiKey=${FASTNEAR_API_KEY:-}" \ | jq '{ height: .block.header.height, timestamp_nanosec: .block.header.timestamp_nanosec, @@ -40,11 +37,8 @@ curl -sL "https://mainnet.neardata.xyz/v0/last_block/final" \ ```bash TARGET_CONTRACT=intents.near -AUTH_HEADER=() -if [ -n "${FASTNEAR_API_KEY:-}" ]; then AUTH_HEADER=(-H "Authorization: Bearer $FASTNEAR_API_KEY"); fi -curl -sL "https://mainnet.neardata.xyz/v0/last_block/final" \ - "${AUTH_HEADER[@]}" \ +curl -sL "https://mainnet.neardata.xyz/v0/last_block/final?apiKey=${FASTNEAR_API_KEY:-}" \ | jq --arg contract "$TARGET_CONTRACT" '{ height: .block.header.height, contract: $contract, @@ -66,8 +60,6 @@ Optimistic-блоки ходят по `/v0/block_opt/{height}` примерно ```bash TARGET_CONTRACT=intents.near -AUTH_HEADER=() -if [ -n "${FASTNEAR_API_KEY:-}" ]; then AUTH_HEADER=(-H "Authorization: Bearer $FASTNEAR_API_KEY"); fi count_touches() { jq --arg contract "$1" ' @@ -78,15 +70,14 @@ count_touches() { } OPT_LOCATION="$( - curl -s -D - -o /dev/null "${AUTH_HEADER[@]}" "https://mainnet.neardata.xyz/v0/last_block/optimistic" \ + curl -s -D - -o /dev/null "https://mainnet.neardata.xyz/v0/last_block/optimistic?apiKey=${FASTNEAR_API_KEY:-}" \ | awk 'tolower($1) == "location:" {print $2}' | tr -d '\r' )" -OPT_HEIGHT="${OPT_LOCATION##*/}" +OPT_PATH="${OPT_LOCATION%%\?*}" +OPT_HEIGHT="${OPT_PATH##*/}" -echo "optimistic @ $OPT_HEIGHT: $(curl -s "https://mainnet.neardata.xyz$OPT_LOCATION" \ - "${AUTH_HEADER[@]}" | count_touches "$TARGET_CONTRACT") touches" -FINAL="$(curl -s "https://mainnet.neardata.xyz/v0/block/$OPT_HEIGHT" \ - "${AUTH_HEADER[@]}")" +echo "optimistic @ $OPT_HEIGHT: $(curl -s "https://mainnet.neardata.xyz$OPT_PATH?apiKey=${FASTNEAR_API_KEY:-}" | count_touches "$TARGET_CONTRACT") touches" +FINAL="$(curl -s "https://mainnet.neardata.xyz/v0/block/$OPT_HEIGHT?apiKey=${FASTNEAR_API_KEY:-}")" if [ "$(printf '%s' "$FINAL" | jq 'type')" = '"null"' ]; then echo "finalized @ $OPT_HEIGHT: not caught up yet" else @@ -102,18 +93,14 @@ fi ```bash TARGET_CONTRACT=intents.near -AUTH_HEADER=() -if [ -n "${FASTNEAR_API_KEY:-}" ]; then AUTH_HEADER=(-H "Authorization: Bearer $FASTNEAR_API_KEY"); fi -HEAD="$(curl -sL "https://mainnet.neardata.xyz/v0/last_block/final" \ - "${AUTH_HEADER[@]}" | jq '.block.header.height')" +HEAD="$(curl -sL "https://mainnet.neardata.xyz/v0/last_block/final?apiKey=${FASTNEAR_API_KEY:-}" | jq '.block.header.height')" FOUND_HEIGHT="" FOUND_SHARD="" for OFFSET in $(seq 0 15); do H=$((HEAD - OFFSET)) - SHARD="$(curl -s "https://mainnet.neardata.xyz/v0/block/$H" \ - "${AUTH_HEADER[@]}" \ + SHARD="$(curl -s "https://mainnet.neardata.xyz/v0/block/$H?apiKey=${FASTNEAR_API_KEY:-}" \ | jq -r --arg contract "$TARGET_CONTRACT" ' .shards[] | select([.state_changes[]? | select(.change.account_id? == $contract)] | length > 0) @@ -128,8 +115,7 @@ done if [ -z "$FOUND_HEIGHT" ]; then echo "no state mutation for $TARGET_CONTRACT in the last 16 finalized blocks" else - curl -s "https://mainnet.neardata.xyz/v0/block/$FOUND_HEIGHT/shard/$FOUND_SHARD" \ - "${AUTH_HEADER[@]}" \ + curl -s "https://mainnet.neardata.xyz/v0/block/$FOUND_HEIGHT/shard/$FOUND_SHARD?apiKey=${FASTNEAR_API_KEY:-}" \ | jq --arg contract "$TARGET_CONTRACT" --argjson height "$FOUND_HEIGHT" --argjson shard_id "$FOUND_SHARD" '{ height: $height, shard_id: $shard_id, diff --git a/i18n/ru/docusaurus-plugin-content-docs/current/rpc/examples.md b/i18n/ru/docusaurus-plugin-content-docs/current/rpc/examples.md index 97b749f..0605b47 100644 --- a/i18n/ru/docusaurus-plugin-content-docs/current/rpc/examples.md +++ b/i18n/ru/docusaurus-plugin-content-docs/current/rpc/examples.md @@ -12,7 +12,7 @@ page_actions: Начинайте с RPC-метода, который отвечает на вопрос. Используйте `tx`, чтобы отследить включение и финальность по хешу транзакции, и расширяйте поверхность только когда нужны дерево receipts, сырой state или трассировка на уровне shard. -Все shell-примеры ниже работают на публичных RPC-хостах как есть. Если в shell задан `FASTNEAR_API_KEY`, они автоматически добавляют bearer header; если переменная не задана, они переходят на публичный неаутентифицированный путь. +Все shell-примеры ниже работают на публичных RPC-хостах как есть. Если в shell задан `FASTNEAR_API_KEY`, они автоматически передают его как query-параметр `apiKey`; если переменная не задана, они переходят на публичный неаутентифицированный путь. Также поддерживается bearer-аутентификация через `Authorization: Bearer ${FASTNEAR_API_KEY}`, если вашему клиенту удобнее передавать ключ в заголовке. ## Состояние аккаунта @@ -22,11 +22,8 @@ page_actions: ```bash ACCOUNT_ID=root.near -AUTH_HEADER=() -if [ -n "${FASTNEAR_API_KEY:-}" ]; then AUTH_HEADER=(-H "Authorization: Bearer $FASTNEAR_API_KEY"); fi -curl -s "https://rpc.mainnet.fastnear.com" \ - "${AUTH_HEADER[@]}" \ +curl -s "https://rpc.mainnet.fastnear.com?apiKey=${FASTNEAR_API_KEY:-}" \ -H 'content-type: application/json' \ --data "$(jq -nc --arg account_id "$ACCOUNT_ID" '{ jsonrpc:"2.0",id:"fastnear",method:"query", @@ -46,11 +43,8 @@ curl -s "https://rpc.mainnet.fastnear.com" \ ```bash TX_HASH=CVyG2xLJ6fuKCtULAxMnWTh2GL5ey2UUiTcgYT3M6Pow SIGNER_ACCOUNT_ID=mike.testnet -AUTH_HEADER=() -if [ -n "${FASTNEAR_API_KEY:-}" ]; then AUTH_HEADER=(-H "Authorization: Bearer $FASTNEAR_API_KEY"); fi -curl -s "https://archival-rpc.testnet.fastnear.com" \ - "${AUTH_HEADER[@]}" \ +curl -s "https://archival-rpc.testnet.fastnear.com?apiKey=${FASTNEAR_API_KEY:-}" \ -H 'content-type: application/json' \ --data "$(jq -nc --arg tx_hash "$TX_HASH" --arg signer_id "$SIGNER_ACCOUNT_ID" '{ jsonrpc: "2.0", id: "fastnear", method: "tx", @@ -79,14 +73,12 @@ curl -s "https://archival-rpc.testnet.fastnear.com" \ ```bash EMPTY_TX_ROOT=11111111111111111111111111111111 -AUTH_HEADER=() -if [ -n "${FASTNEAR_API_KEY:-}" ]; then AUTH_HEADER=(-H "Authorization: Bearer $FASTNEAR_API_KEY"); fi -BLOCK_HASH="$(curl -s "https://rpc.mainnet.fastnear.com" "${AUTH_HEADER[@]}" -H 'content-type: application/json' \ +BLOCK_HASH="$(curl -s "https://rpc.mainnet.fastnear.com?apiKey=${FASTNEAR_API_KEY:-}" -H 'content-type: application/json' \ --data '{"jsonrpc":"2.0","id":"fastnear","method":"status","params":[]}' \ | jq -r '.result.sync_info.latest_block_hash')" -CHUNK_HASH="$(curl -s "https://rpc.mainnet.fastnear.com" "${AUTH_HEADER[@]}" -H 'content-type: application/json' \ +CHUNK_HASH="$(curl -s "https://rpc.mainnet.fastnear.com?apiKey=${FASTNEAR_API_KEY:-}" -H 'content-type: application/json' \ --data "$(jq -nc --arg block_hash "$BLOCK_HASH" '{ jsonrpc:"2.0",id:"fastnear",method:"block",params:{block_id:$block_hash} }')" \ @@ -96,7 +88,7 @@ CHUNK_HASH="$(curl -s "https://rpc.mainnet.fastnear.com" "${AUTH_HEADER[@]}" -H if [ -z "$CHUNK_HASH" ]; then echo "tip block had no transactions in any chunk — rerun on the next head" else - curl -s "https://rpc.mainnet.fastnear.com" "${AUTH_HEADER[@]}" -H 'content-type: application/json' \ + curl -s "https://rpc.mainnet.fastnear.com?apiKey=${FASTNEAR_API_KEY:-}" -H 'content-type: application/json' \ --data "$(jq -nc --arg chunk_hash "$CHUNK_HASH" '{ jsonrpc:"2.0",id:"fastnear",method:"chunk",params:{chunk_id:$chunk_hash} }')" \ @@ -136,11 +128,8 @@ fi ```bash ACCOUNT_ID=root.near RECEIVER_ID=social.near -AUTH_HEADER=() -if [ -n "${FASTNEAR_API_KEY:-}" ]; then AUTH_HEADER=(-H "Authorization: Bearer $FASTNEAR_API_KEY"); fi -curl -s "https://rpc.mainnet.fastnear.com" \ - "${AUTH_HEADER[@]}" \ +curl -s "https://rpc.mainnet.fastnear.com?apiKey=${FASTNEAR_API_KEY:-}" \ -H 'content-type: application/json' \ --data "$(jq -nc --arg account_id "$ACCOUNT_ID" '{ jsonrpc:"2.0",id:"fastnear",method:"query", @@ -178,10 +167,8 @@ View-метод вроде `get_num` всё равно заставляет уз ```bash CONTRACT_ID=counter.near-examples.testnet -AUTH_HEADER=() -if [ -n "${FASTNEAR_API_KEY:-}" ]; then AUTH_HEADER=(-H "Authorization: Bearer $FASTNEAR_API_KEY"); fi -RAW_B64="$(curl -s "https://rpc.testnet.fastnear.com" "${AUTH_HEADER[@]}" -H 'content-type: application/json' \ +RAW_B64="$(curl -s "https://rpc.testnet.fastnear.com?apiKey=${FASTNEAR_API_KEY:-}" -H 'content-type: application/json' \ --data "$(jq -nc --arg contract "$CONTRACT_ID" '{ jsonrpc:"2.0",id:"fastnear",method:"query", params:{request_type:"view_state",account_id:$contract,prefix_base64:"U1RBVEU=",finality:"final"} @@ -208,12 +195,10 @@ jq -n --arg raw "$RAW_B64" --argjson val "$DECODED_I8" '{raw_bytes_base64: $raw, ```bash ACCOUNT_ID=root.near # account you're writing under SIGNER_ACCOUNT_ID=root.near # account signing the transaction -AUTH_HEADER=() -if [ -n "${FASTNEAR_API_KEY:-}" ]; then AUTH_HEADER=(-H "Authorization: Bearer $FASTNEAR_API_KEY"); fi STORAGE_ARGS_B64="$(jq -nc --arg account_id "$ACCOUNT_ID" '{account_id:$account_id}' | base64 | tr -d '\n')" -STORAGE="$(curl -s "https://rpc.mainnet.fastnear.com" "${AUTH_HEADER[@]}" -H 'content-type: application/json' \ +STORAGE="$(curl -s "https://rpc.mainnet.fastnear.com?apiKey=${FASTNEAR_API_KEY:-}" -H 'content-type: application/json' \ --data "$(jq -nc --arg args "$STORAGE_ARGS_B64" '{ jsonrpc:"2.0",id:"fastnear",method:"query", params:{request_type:"call_function",account_id:"social.near",method_name:"get_account_storage",args_base64:$args,finality:"final"} @@ -224,7 +209,7 @@ if [ "$SIGNER_ACCOUNT_ID" = "$ACCOUNT_ID" ]; then PERMISSION=true else PERM_ARGS_B64="$(jq -nc --arg pred "$SIGNER_ACCOUNT_ID" --arg key "$ACCOUNT_ID" '{predecessor_id:$pred,key:$key}' | base64 | tr -d '\n')" - PERMISSION="$(curl -s "https://rpc.mainnet.fastnear.com" "${AUTH_HEADER[@]}" -H 'content-type: application/json' \ + PERMISSION="$(curl -s "https://rpc.mainnet.fastnear.com?apiKey=${FASTNEAR_API_KEY:-}" -H 'content-type: application/json' \ --data "$(jq -nc --arg args "$PERM_ARGS_B64" '{ jsonrpc:"2.0",id:"fastnear",method:"query", params:{request_type:"call_function",account_id:"social.near",method_name:"is_write_permission_granted",args_base64:$args,finality:"final"} @@ -251,15 +236,13 @@ SocialDB хранит BOS-виджеты как ключи `/widget/