Graph Transaction Signing

To sign and broadcast the transaction to the Gprah network, follow these steps:

  1. Prepare unsigned transaction in JSON format. Obtain the unsignedTransactionData field from the Unified API (staking, approval, unstake, or withdrawal).
    This field contains the full EIP-1559 transaction as a JSON string.

  2. Sign the transaction using the following code:

import { ethers } from 'ethers';

// Replace with your wallet mnemonic and Arbitrum RPC URL
const MNEMONIC = '<YOUR_MNEMONIC>';
const RPC_URL = '<ARBITRUM_RPC_URL>'; // e.g., https://arb1.arbitrum.io/rpc
const UNSIGNED_TX_JSON = `<UNSIGNED_TRANSACTION_DATA_FROM_API>`; // Stringified JSON from API

async function main() {
    if (!UNSIGNED_TX_JSON || UNSIGNED_TX_JSON.length < 10) {
        throw new Error("❌ UNSIGNED_TX_JSON is missing or invalid.");
    }

    // Parse the unsigned transaction data
    const txData = JSON.parse(UNSIGNED_TX_JSON);

    // Set up provider and wallet
    const provider = new ethers.providers.JsonRpcProvider(RPC_URL);
    const wallet = ethers.Wallet.fromMnemonic(MNEMONIC).connect(provider);

    // Prepare the EIP-1559 transaction
    const tx: ethers.providers.TransactionRequest = {
        from: txData.from,
        to: txData.to,
        data: txData.data,
        nonce: txData.nonce,
        gasLimit: ethers.BigNumber.from(txData.gasLimit),
        maxFeePerGas: ethers.BigNumber.from(txData.maxFeePerGas),
        maxPriorityFeePerGas: ethers.BigNumber.from(txData.maxPriorityFeePerGas),
        chainId: txData.chainId,
        type: txData.type, // 2 for EIP-1559
    };

    // Sign the transaction (returns raw transaction hex)
    const signedTx = await wallet.signTransaction(tx);

    console.log("✅ Signed The Graph (Arbitrum) Tx (hex):");
    console.log(signedTx);
}

main().catch(console.error);

Upon successful execution, the script prints the signed transaction in hexadecimal format, ready to be broadcasted:

✅ Signed The Graph (Arbitrum) Tx (hex): 0x...
  1. Broadcast the transaction to the Graph network by sending a POST request to /api/v1/unified/transaction/broadcast.

What's Next?