Query a Contract Method
Use this guide to perform a read-only query against a deployed contract. Unlike a call, this does not produce a blockchain transaction and is free of gas fees.
Prerequisites
Section titled “Prerequisites”Before you begin, ensure:
- The contract ABI is uploaded
- The contract deployment is registered
- You have the
deploymentId
and method name
Endpoint
Section titled “Endpoint”POST /v2/contract/deployment/{id}/query
Request Parameters
{ "method": "balanceOf", "params": ["0xabc123..."]}
method
: The name of the method to queryparams
: An array of arguments in the same order as the method signature
Example Request
curl -X POST https://api.fsco.io/v2/contract/deployment/dep_abc123/query \ -H "Authorization: Bearer $FSCO_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "methodName": "balanceOf", "paramCollection": ["0xabc"], "isShared": false }'
import axios from 'axios';
const FSCO_API_KEY = process.env.FSCO_API_KEY;
const queryMethod = async () => { const response = await axios.post( 'https://api.fsco.io/v2/contract/deployment/dep_abc123/query', { methodName: 'balanceOf', paramCollection: ['0xabc'], isShared: false }, { headers: { Authorization: `Bearer ${FSCO_API_KEY}`, 'Content-Type': 'application/json' } } );
console.log('Contract query result:', response.data);};
queryMethod();
import requestsimport os
FSCO_API_KEY = os.getenv("FSCO_API_KEY")
headers = { "Authorization": f"Bearer {FSCO_API_KEY}", "Content-Type": "application/json",}
payload = {"methodName": "balanceOf", "paramCollection": ["0xabc"], "isShared": False}
response = requests.post( "https://api.fsco.io/v2/contract/deployment/dep_abc123/query", json=payload, headers=headers,)
print("Contract query result:", response.json())
using System;using System.Net.Http;using System.Net.Http.Headers;using System.Text;using System.Threading.Tasks;
class Program{ static async Task Main() { var apiKey = Environment.GetEnvironmentVariable("FSCO_API_KEY");
var client = new HttpClient(); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);
var json = @"{ ""methodName"": ""balanceOf"", ""paramCollection"": [""0xabc""], ""isShared"": false }"; var content = new StringContent(json, Encoding.UTF8, "application/json");
var response = await client.PostAsync("https://api.fsco.io/v2/contract/deployment/dep_abc123/query", content); var responseString = await response.Content.ReadAsStringAsync();
Console.WriteLine("Contract query result: " + responseString); }}
Response
{ "query": { "deploymentId": "uuid", "methodName": "balanceOf", "paramCollection": ["0xabc"], "isShared": false }, "response": { "balance": "1000000000000000000" }}
Important Notes
Section titled “Important Notes”- This request does not modify blockchain state
- This request does not require a wallet
- The query is executed on the latest block
- The response is returned immediately
- Make sure the method you’re calling is marked
view
orpure
in the ABI - This is ideal for checking balances, ownerOf, or any informational method