run-script-view - Tezos

Executes an on-chain view of a smart contract and returns its result, without creating a transaction. Views are read-only contract functions.

Endpoint

httpPOST /chains/main/blocks/{block}/helpers/scripts/run_script_view

Path Parameters

ParameterTypeDescription
blockstringBlock identifier: head, a level, or a block hash

Example

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

curl -X POST "${TEZOS_REST}chains/main/blocks/head/helpers/scripts/run_script_view" \
  -H "Content-Type: application/json" \
  -d '{"contract": "KT1BuEZtb68c1Q4yjtckcNjGELqWt56Xyesc", "view": "get_balance", "input": {"string": "tz1..."}, "chain_id": "NetXdQprcVkpaWU", "unparsing_mode": "Readable"}'

example.js

javascriptconst axios = require('axios');

const response = await axios.post('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/chains/main/blocks/head/helpers/scripts/run_script_view', {
    contract: 'KT1BuEZtb68c1Q4yjtckcNjGELqWt56Xyesc',
    view: 'get_balance',
    input: { string: 'tz1...' },
    chain_id: 'NetXdQprcVkpaWU',
    unparsing_mode: 'Readable'
}, {
    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>/chains/main/blocks/head/helpers/scripts/run_script_view',
    headers={'Content-Type': 'application/json'},
    json={
        'contract': 'KT1BuEZtb68c1Q4yjtckcNjGELqWt56Xyesc',
        'view': 'get_balance',
        'input': {'string': 'tz1...'},
        'chain_id': 'NetXdQprcVkpaWU',
        'unparsing_mode': 'Readable'
    }
)

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>/chains/main/blocks/head/helpers/scripts/run_script_view")
        .header("Content-Type", "application/json")
        .json(&json!({
            "contract": "KT1BuEZtb68c1Q4yjtckcNjGELqWt56Xyesc",
            "view": "get_balance",
            "input": { "string": "tz1..." },
            "chain_id": "NetXdQprcVkpaWU",
            "unparsing_mode": "Readable"
        }))
        .send()
        .await?
        .json::<Value>()
        .await?;

    println!("Result: {}", response);
    Ok(())
}

Response

json{
    "data": {
        "int": "1000000"
    }
}

Response Fields

FieldTypeDescription
dataobjectThe view's return value as a Micheline expression

Use Cases

  • Read-Only Calls: Query a contract view without a transaction
  • Token Metadata: Resolve FA2 balances/metadata via views

Error Handling

ErrorMessageDescription
400 / Bad requestBad requestA path or body parameter was invalid
404 / Not foundNot foundThe block, contract, or resource does not exist
403 / RBAC: access deniedAccess deniedThe GetBlock access token is missing or incorrect