Skip to main content
POST
/
api
/
v1
/
contracts
/
call
Invoke a smart contract
curl --request POST \
  --url https://api.example.com/api/v1/contracts/call \
  --header 'Content-Type: application/json' \
  --data '
{
  "to": "0xd9d0c5c0ff85758bdf05a7636f8036d4d065f5b6",
  "block": "latest",
  "data": "0x47f1aae7",
  "estimate": true,
  "from": "00000000000000000000000000000000000004e2",
  "gas": 15000000,
  "gasPrice": 100000000,
  "value": 0
}
'
import requests

url = "https://api.example.com/api/v1/contracts/call"

payload = {
"to": "0xd9d0c5c0ff85758bdf05a7636f8036d4d065f5b6",
"block": "latest",
"data": "0x47f1aae7",
"estimate": True,
"from": "00000000000000000000000000000000000004e2",
"gas": 15000000,
"gasPrice": 100000000,
"value": 0
}
headers = {"Content-Type": "application/json"}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
to: '0xd9d0c5c0ff85758bdf05a7636f8036d4d065f5b6',
block: 'latest',
data: '0x47f1aae7',
estimate: true,
from: '00000000000000000000000000000000000004e2',
gas: 15000000,
gasPrice: 100000000,
value: 0
})
};

fetch('https://api.example.com/api/v1/contracts/call', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));
<?php

$curl = curl_init();

curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/api/v1/contracts/call",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'to' => '0xd9d0c5c0ff85758bdf05a7636f8036d4d065f5b6',
'block' => 'latest',
'data' => '0x47f1aae7',
'estimate' => true,
'from' => '00000000000000000000000000000000000004e2',
'gas' => 15000000,
'gasPrice' => 100000000,
'value' => 0
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
package main

import (
"fmt"
"strings"
"net/http"
"io"
)

func main() {

url := "https://api.example.com/api/v1/contracts/call"

payload := strings.NewReader("{\n \"to\": \"0xd9d0c5c0ff85758bdf05a7636f8036d4d065f5b6\",\n \"block\": \"latest\",\n \"data\": \"0x47f1aae7\",\n \"estimate\": true,\n \"from\": \"00000000000000000000000000000000000004e2\",\n \"gas\": 15000000,\n \"gasPrice\": 100000000,\n \"value\": 0\n}")

req, _ := http.NewRequest("POST", url, payload)

req.Header.Add("Content-Type", "application/json")

res, _ := http.DefaultClient.Do(req)

defer res.Body.Close()
body, _ := io.ReadAll(res.Body)

fmt.Println(string(body))

}
HttpResponse<String> response = Unirest.post("https://api.example.com/api/v1/contracts/call")
.header("Content-Type", "application/json")
.body("{\n \"to\": \"0xd9d0c5c0ff85758bdf05a7636f8036d4d065f5b6\",\n \"block\": \"latest\",\n \"data\": \"0x47f1aae7\",\n \"estimate\": true,\n \"from\": \"00000000000000000000000000000000000004e2\",\n \"gas\": 15000000,\n \"gasPrice\": 100000000,\n \"value\": 0\n}")
.asString();
require 'uri'
require 'net/http'

url = URI("https://api.example.com/api/v1/contracts/call")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"to\": \"0xd9d0c5c0ff85758bdf05a7636f8036d4d065f5b6\",\n \"block\": \"latest\",\n \"data\": \"0x47f1aae7\",\n \"estimate\": true,\n \"from\": \"00000000000000000000000000000000000004e2\",\n \"gas\": 15000000,\n \"gasPrice\": 100000000,\n \"value\": 0\n}"

response = http.request(request)
puts response.read_body
{
  "result": "0x0000000000006d8d"
}
{
"_status": {
"messages": [
{
"data": "0x3000",
"detail": "Generic detailed error message",
"message": "Generic error message"
}
]
}
}
{
"_status": {
"messages": [
{
"data": "0x3000",
"detail": "Generic detailed error message",
"message": "Generic error message"
}
]
}
}
{
"_status": {
"messages": [
{
"data": "0x3000",
"detail": "Generic detailed error message",
"message": "Generic error message"
}
]
}
}
{
"_status": {
"messages": [
{
"data": "0x3000",
"detail": "Generic detailed error message",
"message": "Generic error message"
}
]
}
}
{
"_status": {
"messages": [
{
"data": "0x3000",
"detail": "Generic detailed error message",
"message": "Generic error message"
}
]
}
}
{
"_status": {
"messages": [
{
"data": "0x3000",
"detail": "Generic detailed error message",
"message": "Generic error message"
}
]
}
}

Body

application/json
to
file
required

The 20-byte hexadecimal EVM address the transaction is directed to.

Required string length: 40 - 42
Pattern: ^(0x)?[A-Fa-f0-9]{40}$
block
string | null

Hexadecimal block number or the string "latest", "pending", "earliest". Defaults to "latest".

Pattern: ^((0x)?[0-9a-fA-F]+|(earliest|pending|latest))$
Example:

"latest"

data
file | null

Hexadecimal method signature and encoded parameters. Up to 131072 bytes as at most 262146 hexadecimal digits including optional leading 0x.

Maximum string length: 262146
Pattern: ^(0x)?[0-9a-fA-F]+$
estimate
boolean | null

Whether gas estimation is called. Defaults to false.

Example:

true

from
file | null

The 20-byte hexadecimal EVM address the transaction is sent from.

Required string length: 40 - 42
Pattern: ^(0x)?[A-Fa-f0-9]{40}$
gas
integer<int64> | null

Gas provided for the transaction execution. Defaults to 15000000.

Required range: x >= 0
Example:

15000000

gasPrice
integer<int64> | null

Gas price used for each paid gas.

Required range: x >= 0
Example:

100000000

value
integer<int64> | null

Value sent with this transaction. Defaults to 0.

Required range: x >= 0
Example:

0

Response

OK

result
file

Result in hexadecimal from executed contract call.

Pattern: ^0x[0-9a-fA-F]+$