Call a write function on a deployed contract
Call a write function on a deployed contract by blockchain native asset id and contract address. This creates an onchain transaction, thus it is an async operation. It returns a transaction id that can be polled for status check
const response: Promise<FireblocksResponse<WriteCallFunctionResponseDto>> = fireblocks.contractInteractions.writeCallFunction(contractInteractionsApiWriteCallFunctionRequest);CompletableFuture<ApiResponse<WriteCallFunctionResponseDto>> response = fireblocks.contractInteractions().writeCallFunction(writeCallFunctionDto, contractAddress, baseAssetId, idempotencyKey);response = fireblocks.contract_interactions.write_call_function(write_call_function_dto, contract_address, base_asset_id, idempotency_key);curl --request POST \
--url https://api.fireblocks.io/v1/contract_interactions/base_asset_id/{baseAssetId}/contract_address/{contractAddress}/functions/write \
--header 'Content-Type: application/json' \
--data '
{
"vaultAccountId": "0",
"abiFunction": {
"stateMutability": "nonpayable",
"type": "function",
"inputs": [
{
"name": "_name",
"type": "string",
"description": "The name of the token",
"internalType": "string",
"components": [
{
"name": "_name",
"type": "string",
"description": "The name of the token",
"internalType": "string",
"components": "<array>"
}
],
"value": "true"
}
],
"outputs": [
{
"name": "_name",
"type": "string",
"description": "The name of the token",
"internalType": "string",
"components": "<array>"
}
],
"name": "<string>",
"description": "<string>"
},
"amount": "12.345",
"feeLevel": "MEDIUM",
"fee": "2000",
"note": "<string>",
"useGasless": false,
"externalId": "0192e4f5-924e-7bb9-8e5b-c748270feb38"
}
'const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
vaultAccountId: '0',
abiFunction: {
stateMutability: 'nonpayable',
type: 'function',
inputs: [
{
name: '_name',
type: 'string',
description: 'The name of the token',
internalType: 'string',
components: [
{
name: '_name',
type: 'string',
description: 'The name of the token',
internalType: 'string',
components: '<array>'
}
],
value: 'true'
}
],
outputs: [
{
name: '_name',
type: 'string',
description: 'The name of the token',
internalType: 'string',
components: '<array>'
}
],
name: '<string>',
description: '<string>'
},
amount: '12.345',
feeLevel: 'MEDIUM',
fee: '2000',
note: '<string>',
useGasless: false,
externalId: '0192e4f5-924e-7bb9-8e5b-c748270feb38'
})
};
fetch('https://api.fireblocks.io/v1/contract_interactions/base_asset_id/{baseAssetId}/contract_address/{contractAddress}/functions/write', 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.fireblocks.io/v1/contract_interactions/base_asset_id/{baseAssetId}/contract_address/{contractAddress}/functions/write",
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([
'vaultAccountId' => '0',
'abiFunction' => [
'stateMutability' => 'nonpayable',
'type' => 'function',
'inputs' => [
[
'name' => '_name',
'type' => 'string',
'description' => 'The name of the token',
'internalType' => 'string',
'components' => [
[
'name' => '_name',
'type' => 'string',
'description' => 'The name of the token',
'internalType' => 'string',
'components' => '<array>'
]
],
'value' => 'true'
]
],
'outputs' => [
[
'name' => '_name',
'type' => 'string',
'description' => 'The name of the token',
'internalType' => 'string',
'components' => '<array>'
]
],
'name' => '<string>',
'description' => '<string>'
],
'amount' => '12.345',
'feeLevel' => 'MEDIUM',
'fee' => '2000',
'note' => '<string>',
'useGasless' => false,
'externalId' => '0192e4f5-924e-7bb9-8e5b-c748270feb38'
]),
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.fireblocks.io/v1/contract_interactions/base_asset_id/{baseAssetId}/contract_address/{contractAddress}/functions/write"
payload := strings.NewReader("{\n \"vaultAccountId\": \"0\",\n \"abiFunction\": {\n \"stateMutability\": \"nonpayable\",\n \"type\": \"function\",\n \"inputs\": [\n {\n \"name\": \"_name\",\n \"type\": \"string\",\n \"description\": \"The name of the token\",\n \"internalType\": \"string\",\n \"components\": [\n {\n \"name\": \"_name\",\n \"type\": \"string\",\n \"description\": \"The name of the token\",\n \"internalType\": \"string\",\n \"components\": \"<array>\"\n }\n ],\n \"value\": \"true\"\n }\n ],\n \"outputs\": [\n {\n \"name\": \"_name\",\n \"type\": \"string\",\n \"description\": \"The name of the token\",\n \"internalType\": \"string\",\n \"components\": \"<array>\"\n }\n ],\n \"name\": \"<string>\",\n \"description\": \"<string>\"\n },\n \"amount\": \"12.345\",\n \"feeLevel\": \"MEDIUM\",\n \"fee\": \"2000\",\n \"note\": \"<string>\",\n \"useGasless\": false,\n \"externalId\": \"0192e4f5-924e-7bb9-8e5b-c748270feb38\"\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))
}require 'uri'
require 'net/http'
url = URI("https://api.fireblocks.io/v1/contract_interactions/base_asset_id/{baseAssetId}/contract_address/{contractAddress}/functions/write")
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 \"vaultAccountId\": \"0\",\n \"abiFunction\": {\n \"stateMutability\": \"nonpayable\",\n \"type\": \"function\",\n \"inputs\": [\n {\n \"name\": \"_name\",\n \"type\": \"string\",\n \"description\": \"The name of the token\",\n \"internalType\": \"string\",\n \"components\": [\n {\n \"name\": \"_name\",\n \"type\": \"string\",\n \"description\": \"The name of the token\",\n \"internalType\": \"string\",\n \"components\": \"<array>\"\n }\n ],\n \"value\": \"true\"\n }\n ],\n \"outputs\": [\n {\n \"name\": \"_name\",\n \"type\": \"string\",\n \"description\": \"The name of the token\",\n \"internalType\": \"string\",\n \"components\": \"<array>\"\n }\n ],\n \"name\": \"<string>\",\n \"description\": \"<string>\"\n },\n \"amount\": \"12.345\",\n \"feeLevel\": \"MEDIUM\",\n \"fee\": \"2000\",\n \"note\": \"<string>\",\n \"useGasless\": false,\n \"externalId\": \"0192e4f5-924e-7bb9-8e5b-c748270feb38\"\n}"
response = http.request(request)
puts response.read_body{
"txId": "<string>"
}{
"message": "<string>",
"code": 123
}Headers
A unique identifier for the request. If the request is sent multiple times with the same idempotency key, the server will return the same response as the first request. The idempotency key is valid for 24 hours.
Path Parameters
The contract's onchain address
Body
The vault account id this contract was deploy from
"0"
- Option 1
- Option 2
Show child attributes
Show child attributes
Amount in base asset. Being used in payable functions
"12.345"
Fee level for the write function transaction. interchangeable with the 'fee' field
LOW, MEDIUM, HIGH "MEDIUM"
Max fee amount for the write function transaction. interchangeable with the 'feeLevel' field
"2000"
Custom note, not sent to the blockchain, that describes the transaction at your Fireblocks workspace
Indicates whether the token should be created in a gasless manner, utilizing the ERC-2771 standard. When set to true, the transaction will be relayed by a designated relayer. The workspace must be configured to use Fireblocks gasless relay.
false
External id that can be used to identify the transaction in your system. The unique identifier of the transaction outside of Fireblocks with max length of 255 characters
"0192e4f5-924e-7bb9-8e5b-c748270feb38"
Response
Was this page helpful?
const response: Promise<FireblocksResponse<WriteCallFunctionResponseDto>> = fireblocks.contractInteractions.writeCallFunction(contractInteractionsApiWriteCallFunctionRequest);CompletableFuture<ApiResponse<WriteCallFunctionResponseDto>> response = fireblocks.contractInteractions().writeCallFunction(writeCallFunctionDto, contractAddress, baseAssetId, idempotencyKey);response = fireblocks.contract_interactions.write_call_function(write_call_function_dto, contract_address, base_asset_id, idempotency_key);curl --request POST \
--url https://api.fireblocks.io/v1/contract_interactions/base_asset_id/{baseAssetId}/contract_address/{contractAddress}/functions/write \
--header 'Content-Type: application/json' \
--data '
{
"vaultAccountId": "0",
"abiFunction": {
"stateMutability": "nonpayable",
"type": "function",
"inputs": [
{
"name": "_name",
"type": "string",
"description": "The name of the token",
"internalType": "string",
"components": [
{
"name": "_name",
"type": "string",
"description": "The name of the token",
"internalType": "string",
"components": "<array>"
}
],
"value": "true"
}
],
"outputs": [
{
"name": "_name",
"type": "string",
"description": "The name of the token",
"internalType": "string",
"components": "<array>"
}
],
"name": "<string>",
"description": "<string>"
},
"amount": "12.345",
"feeLevel": "MEDIUM",
"fee": "2000",
"note": "<string>",
"useGasless": false,
"externalId": "0192e4f5-924e-7bb9-8e5b-c748270feb38"
}
'const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
vaultAccountId: '0',
abiFunction: {
stateMutability: 'nonpayable',
type: 'function',
inputs: [
{
name: '_name',
type: 'string',
description: 'The name of the token',
internalType: 'string',
components: [
{
name: '_name',
type: 'string',
description: 'The name of the token',
internalType: 'string',
components: '<array>'
}
],
value: 'true'
}
],
outputs: [
{
name: '_name',
type: 'string',
description: 'The name of the token',
internalType: 'string',
components: '<array>'
}
],
name: '<string>',
description: '<string>'
},
amount: '12.345',
feeLevel: 'MEDIUM',
fee: '2000',
note: '<string>',
useGasless: false,
externalId: '0192e4f5-924e-7bb9-8e5b-c748270feb38'
})
};
fetch('https://api.fireblocks.io/v1/contract_interactions/base_asset_id/{baseAssetId}/contract_address/{contractAddress}/functions/write', 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.fireblocks.io/v1/contract_interactions/base_asset_id/{baseAssetId}/contract_address/{contractAddress}/functions/write",
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([
'vaultAccountId' => '0',
'abiFunction' => [
'stateMutability' => 'nonpayable',
'type' => 'function',
'inputs' => [
[
'name' => '_name',
'type' => 'string',
'description' => 'The name of the token',
'internalType' => 'string',
'components' => [
[
'name' => '_name',
'type' => 'string',
'description' => 'The name of the token',
'internalType' => 'string',
'components' => '<array>'
]
],
'value' => 'true'
]
],
'outputs' => [
[
'name' => '_name',
'type' => 'string',
'description' => 'The name of the token',
'internalType' => 'string',
'components' => '<array>'
]
],
'name' => '<string>',
'description' => '<string>'
],
'amount' => '12.345',
'feeLevel' => 'MEDIUM',
'fee' => '2000',
'note' => '<string>',
'useGasless' => false,
'externalId' => '0192e4f5-924e-7bb9-8e5b-c748270feb38'
]),
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.fireblocks.io/v1/contract_interactions/base_asset_id/{baseAssetId}/contract_address/{contractAddress}/functions/write"
payload := strings.NewReader("{\n \"vaultAccountId\": \"0\",\n \"abiFunction\": {\n \"stateMutability\": \"nonpayable\",\n \"type\": \"function\",\n \"inputs\": [\n {\n \"name\": \"_name\",\n \"type\": \"string\",\n \"description\": \"The name of the token\",\n \"internalType\": \"string\",\n \"components\": [\n {\n \"name\": \"_name\",\n \"type\": \"string\",\n \"description\": \"The name of the token\",\n \"internalType\": \"string\",\n \"components\": \"<array>\"\n }\n ],\n \"value\": \"true\"\n }\n ],\n \"outputs\": [\n {\n \"name\": \"_name\",\n \"type\": \"string\",\n \"description\": \"The name of the token\",\n \"internalType\": \"string\",\n \"components\": \"<array>\"\n }\n ],\n \"name\": \"<string>\",\n \"description\": \"<string>\"\n },\n \"amount\": \"12.345\",\n \"feeLevel\": \"MEDIUM\",\n \"fee\": \"2000\",\n \"note\": \"<string>\",\n \"useGasless\": false,\n \"externalId\": \"0192e4f5-924e-7bb9-8e5b-c748270feb38\"\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))
}require 'uri'
require 'net/http'
url = URI("https://api.fireblocks.io/v1/contract_interactions/base_asset_id/{baseAssetId}/contract_address/{contractAddress}/functions/write")
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 \"vaultAccountId\": \"0\",\n \"abiFunction\": {\n \"stateMutability\": \"nonpayable\",\n \"type\": \"function\",\n \"inputs\": [\n {\n \"name\": \"_name\",\n \"type\": \"string\",\n \"description\": \"The name of the token\",\n \"internalType\": \"string\",\n \"components\": [\n {\n \"name\": \"_name\",\n \"type\": \"string\",\n \"description\": \"The name of the token\",\n \"internalType\": \"string\",\n \"components\": \"<array>\"\n }\n ],\n \"value\": \"true\"\n }\n ],\n \"outputs\": [\n {\n \"name\": \"_name\",\n \"type\": \"string\",\n \"description\": \"The name of the token\",\n \"internalType\": \"string\",\n \"components\": \"<array>\"\n }\n ],\n \"name\": \"<string>\",\n \"description\": \"<string>\"\n },\n \"amount\": \"12.345\",\n \"feeLevel\": \"MEDIUM\",\n \"fee\": \"2000\",\n \"note\": \"<string>\",\n \"useGasless\": false,\n \"externalId\": \"0192e4f5-924e-7bb9-8e5b-c748270feb38\"\n}"
response = http.request(request)
puts response.read_body{
"txId": "<string>"
}{
"message": "<string>",
"code": 123
}