Sign a Transaction
Prerequisites
Section titled “Prerequisites”Before you can sign a transaction, you need:
- A valid FSCO API key
- A wallet ID for the wallet you want to use for signing
- The transaction data to sign in hex format
Endpoint
Section titled “Endpoint”POST /v2/wallet/{walletId}/sign/tx
Parameters
Section titled “Parameters”Parameter | Type | Required | Description |
---|---|---|---|
walletId | string | Yes | The unique ID of the wallet to use for signing |
data | string | Yes | The transaction data to be signed in hex format (must start with ‘0x’) |
Examples
Section titled “Examples”#!/bin/bash
curl -X POST "https://api.fsco.io/v2/wallet/8c1d496f-2827-4750-a11f-74b48c11108d/sign/tx" \ -H "Authorization: Bearer ${FSCO_API_KEY}" \ -H "Content-Type: application/json" \ -d '{ "walletId": "8c1d496f-2827-4750-a11f-74b48c11108d", "data": "0x02f87082000189059682f00085059682f10825208947..." }'
import axios from 'axios';
const FSCO_API_KEY = process.env.FSCO_API_KEY;const FSCO_API_SECRET = process.env.FSCO_API_SECRET;const walletId = '8c1d496f-2827-4750-a11f-74b48c11108d';
async function signTransaction() { try { const response = await axios.post( `https://api.fsco.io/v2/wallet/${walletId}/sign/tx`, { walletId, data: '0x02f87082000189059682f00085059682f10825208947...' }, { headers: { 'Content-Type': 'application/json', 'x-api-key': FSCO_API_KEY, 'x-api-secret': FSCO_API_SECRET } } );
console.log('Signed transaction:', response.data); return response.data; } catch (error) { console.error('Error signing transaction:', error); throw error; }}
signTransaction();
import osimport requests
FSCO_API_KEY = os.environ.get("FSCO_API_KEY")FSCO_API_SECRET = os.environ.get("FSCO_API_SECRET")wallet_id = "8c1d496f-2827-4750-a11f-74b48c11108d"
def sign_transaction(): try: response = requests.post( f"https://api.fsco.io/v2/wallet/{wallet_id}/sign/tx", json={ "walletId": wallet_id, "data": "0x02f87082000189059682f00085059682f10825208947...", }, headers={ "Content-Type": "application/json", "x-api-key": FSCO_API_KEY, "x-api-secret": FSCO_API_SECRET }, ) response.raise_for_status() print("Signed transaction:", response.json()) return response.json() except requests.exceptions.RequestException as e: print("Error signing transaction:", e) raise
if __name__ == "__main__": sign_transaction()
using System;using System.Net.Http;using System.Text;using System.Text.Json;using System.Threading.Tasks;
class Program{ static readonly string FSCO_API_KEY = Environment.GetEnvironmentVariable("FSCO_API_KEY"); static readonly string walletId = "8c1d496f-2827-4750-a11f-74b48c11108d";
static async Task Main() { await SignTransaction(); }
static async Task SignTransaction() { try { using var client = new HttpClient(); client.DefaultRequestHeaders.Add("Authorization", $"Bearer {FSCO_API_KEY}");
var request = new { walletId = walletId, data = "0x02f87082000189059682f00085059682f10825208947..." };
var content = new StringContent( JsonSerializer.Serialize(request), Encoding.UTF8, "application/json" );
var response = await client.PostAsync( $"https://api.fsco.io/v2/wallet/{walletId}/sign/tx", content );
response.EnsureSuccessStatusCode(); var result = await response.Content.ReadAsStringAsync(); Console.WriteLine($"Signed transaction: {result}"); } catch (Exception ex) { Console.WriteLine($"Error signing transaction: {ex.Message}"); throw; } }}
Response
Section titled “Response”{ "walletId": "8c1d496f-2827-4750-a11f-74b48c11108d", "signedData": "0x02f87082000189059682f00085059682f10825208947..."}
The response includes:
walletId
: The ID of the wallet that signed the transactionsignedData
: The signed transaction data in hex format
- The transaction data must be in hex format and start with ‘0x’
- The wallet must exist and be active
- The signed transaction is automatically broadcast to the network
- The walletId in the path must match the walletId in the request body