execute-script - Flow
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
httpPOST /v1/scriptsQuery Parameters
| Parameter | Type | Description |
|---|---|---|
| block_height | string | Block height, or final / sealed |
| block_id | string | Execute at a specific block ID |
Example
bashexport 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
javascriptconst 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
pythonimport 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())example.rs
rustuse reqwest::Client;
use serde_json::{json, Value};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = Client::new();
let response = client
.post("https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/v1/scripts")
.query(&[("block_height", "sealed")])
.header("Content-Type", "application/json")
.json(&json!({
"script": "cHViIGZ1biBtYWluKCk6IEludCB7IHJldHVybiAxICsgMSB9",
"arguments": []
}))
.send()
.await?
.json::<Value>()
.await?;
println!("Result: {}", response);
Ok(())
}Response
json"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 |