Call a Contract Method
Once your contract is registered, you can interact with it by calling a method that changes state. This guide shows you how to send a transaction to a deployed contract using FSCO’s API.
Prerequisites
Section titled “Prerequisites”Before you begin, ensure:
- You have uploaded the contract ABI
- The deployment is registered
- You know the
deploymentId
and method name - You have a wallet to sign and send the transaction
Endpoint
Section titled “Endpoint”POST /v2/contract/deployment/{id}/call
Request Parameters
{ "walletId": "your-wallet-id", "method": "transfer", "params": ["0xreceiver", "1000000000000000000"]}
The request requires:
walletId
: The FSCO wallet ID that will sign and send the transactionmethod
: The name of the method to call (must exist in the ABI)params
: An array of arguments in the same order as the method signature
Example Request
curl -X POST https://api.fsco.io/v2/contract/deployment/{{deploymentId}}/call \ -H "Authorization: Bearer $FSCO_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "walletId": "{{walletId}}", "methodName": "transfer", "paramCollection": ["0xreceiver", "1000000000000000000"], "isShared": false }'
import axios from 'axios';
const FSCO_API_KEY = process.env.FSCO_API_KEY;
const callMethod = async () => { const response = await axios.post( 'https://api.fsco.io/v2/contract/deployment/{{deploymentId}}/call', { walletId: '{{walletId}}', methodName: 'transfer', paramCollection: ['0xreceiver', '1000000000000000000'], isShared: false }, { headers: { Authorization: `Bearer ${FSCO_API_KEY}`, 'Content-Type': 'application/json' } } );
console.log('Contract method called:', response.data);};
callMethod();
import requestsimport os
FSCO_API_KEY = os.getenv("FSCO_API_KEY")
headers = { "Authorization": f"Bearer {FSCO_API_KEY}", "Content-Type": "application/json",}
payload = { "walletId": "{{walletId}}", "methodName": "transfer", "paramCollection": ["0xreceiver", "1000000000000000000"], "isShared": False,}
response = requests.post( "https://api.fsco.io/v2/contract/deployment/{{deploymentId}}/call", json=payload, headers=headers,)
print("Contract method called:", 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 = @"{ ""walletId"": ""{{walletId}}"", ""methodName"": ""transfer"", ""paramCollection"": [""0xreceiver"", ""1000000000000000000""], ""isShared"": false }"; var content = new StringContent(json, Encoding.UTF8, "application/json");
var response = await client.PostAsync("https://api.fsco.io/v2/contract/deployment/{{deploymentId}}/call", content); var responseString = await response.Content.ReadAsStringAsync();
Console.WriteLine("Contract method called: " + responseString); }}
Response
{ "queryId": "uuid-string"}
Important Notes
Section titled “Important Notes”- Ensure the wallet has sufficient native tokens to cover gas
- Use a separate guide if you only want to query a method without changing state
- The transaction will be broadcast to the chain immediately