For the complete documentation index, see llms.txt. This page is also available as Markdown.

execute-script - Flow

Example code for the /v1/scripts REST method. Complete guide on how to use the /v1/scripts REST method in GetBlock Web3 documentation

Executes a read-only Cadence script against the chain state and returns the base64-encoded JSON-Cadence result. Scripts cannot change state. Pin execution to a block with the block_height or block_id query parameter.

Endpoint

POST /v1/scripts

Query Parameters

Parameter
Type
Description

block_height

string

Block height, or final / sealed

block_id

string

Execute at a specific block ID

Example

export FLOW_REST=https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/

curl -X POST "${FLOW_REST}v1/scripts?block_height=sealed" \
  -H "Content-Type: application/json" \
  -d '{"script": "cHViIGZ1biBtYWluKCk6IEludCB7IHJldHVybiAxICsgMSB9", "arguments": []}'
example.js
const axios = require('axios');

const response = await axios.post('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/v1/scripts', {
    script: 'cHViIGZ1biBtYWluKCk6IEludCB7IHJldHVybiAxICsgMSB9',
    arguments: []
}, {
    params: { block_height: 'sealed' },
    headers: { 'Content-Type': 'application/json' }
});

console.log(response.data);
example.py
import requests

response = requests.post(
    'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/v1/scripts',
    headers={'Content-Type': 'application/json'},
    params={'block_height': 'sealed'},
    json={
        'script': 'cHViIGZ1biBtYWluKCk6IEludCB7IHJldHVybiAxICsgMSB9',
        'arguments': []
    }
)

print(response.json())

Response

"eyJ0eXBlIjoiSW50IiwidmFsdWUiOiIyIn0="

Response Fields

Field
Type
Description

(root)

string

Base64-encoded JSON-Cadence return value

Use Cases

  • Read-Only Queries: Run a Cadence script to read chain state

  • Balance & Metadata: Resolve token balances and NFT metadata via scripts

Error Handling

Error
Message
Description

400 / Bad request

Bad request

A path, query, or body parameter was invalid

404 / Not found

Not found

The block, account, transaction, or resource does not exist

403 / RBAC: access denied

Access denied

The GetBlock access token is missing or incorrect

Was this helpful?