# Broadcast

#### 6. Send a transaction to the network

**POST** `/hyperliquid/staking/broadcast`

Broadcast a signed transaction to the Hyperliquid network.

**Request Body**

```json
{
  "signedTransaction": "eyJhY3Rpb24iOnsidHlwZSI6ImNEZXBvc2l0IiwiaHlwZXJsaXF1aWRDaGFpbiI6IlRlc3RuZXQiLCJzaWduYXR1cmVDaGFpbklkIjoiMHg2NmVlZSIsIndlaSI6MTUwMDAwMDAwLCJub25jZSI6MTcwNzEyMzQ1Njc4OX0sIm5vbmNlIjoxNzA3MTIzNDU2Nzg5LCJzaWduYXR1cmUiOnsiciI6IjB4MTIzNDU2Nzg5MGFiY2RlZi4uLiIsInMiOiIweGZlZGNiYTA5ODc2NTQzMjEuLi4iLCJ2IjoyN319"
}
```

**Parameters**

* `signedTransaction` (string, required): Base64 encoded signed transaction

**Response**

```json
{
  "result": {
    "transactionHash": "0xabc123def456...",
    "status": "success",
    "createdAt": "2025-01-21T12:00:00.000Z"
  }
}
```

**cURL Example**

```bash
curl --location '{{url}}/api/v1/staking/broadcast' \
--header 'api-key: your-api-key' \
--data '{
  "signedTransaction": "eyJhY3Rpb24iOnsidHlwZSI6ImNEZXBvc2l0IiwiaHlwZXJsaXF1aWRDaGFpbiI6IlRlc3RuZXQiLCJzaWduYXR1cmVDaGFpbklkIjoiMHg2NmVlZSIsIndlaSI6MTUwMDAwMDAwLCJub25jZSI6MTcwNzEyMzQ1Njc4OX0sIm5vbmNlIjoxNzA3MTIzNDU2Nzg5LCJzaWduYXR1cmUiOnsiciI6IjB4MTIzNDU2Nzg5MGFiY2RlZi4uLiIsInMiOiIweGZlZGNiYTA5ODc2NTQzMjEuLi4iLCJ2IjoyN319"
}'
```

***

### Client-Side Signing

To sign the unsigned transaction received from the API:

```javascript
// Extract unsigned transaction from API response
const apiResponse = {
  "result": {
    "amount": "1.5",
    "unsignedTransactionBase64": "eyJhY3Rpb24iOi...", // base64 string from API
    "createdAt": "2025-01-21T12:00:00.000Z"
  }
};

// Decode the base64 unsigned transaction
const unsignedTx = JSON.parse(atob(apiResponse.result.unsignedTransactionBase64));

// Sign with ethers.js
const wallet = new ethers.Wallet(privateKey);
const signature = await wallet.signTypedData(
  unsignedTx.domain, 
  unsignedTx.types, 
  unsignedTx.action
);

// Create signed transaction (signature is a hex string)
const signedTx = {
  action: unsignedTx.action,
  nonce: unsignedTx.nonce,
  signature: {
    r: "0x" + signature.slice(2, 66),
    s: "0x" + signature.slice(66, 130),
    v: parseInt(signature.slice(130, 132), 16)
  }
};

// Encode as base64 for broadcast API
const signedTransaction = btoa(JSON.stringify(signedTx));

// Use signedTransaction in broadcast request
const broadcastResponse = await fetch('https://staking.luganodes.com/hyperliquid/mainnet/api/v1/staking/broadcast', {
  method: 'POST',
  headers: {
    'api-key': 'your-api-key',
    'content-type': 'application/json'
  },
  body: JSON.stringify({
    signedTransaction: signedTransaction
  })
});
```

#### Complete Workflow Example

```javascript
async function stakingWorkflow(privateKey, amount, delegatorAddress) {
  // Step 1: Get unsigned transaction
  const transferResponse = await fetch('https://staking.luganodes.com/hyperliquid/mainnet/api/v1/staking/transfer', {
    method: 'POST',
    headers: {
      'api-key': 'your-api-key',
      'content-type': 'application/json'
    },
    body: JSON.stringify({
      amount: amount,
      delegatorAddress: delegatorAddress
    })
  });
  
  const transferData = await transferResponse.json();
  
  // Step 2: Sign the transaction
  const unsignedTx = JSON.parse(atob(transferData.result.unsignedTransactionBase64));
  const wallet = new ethers.Wallet(privateKey);
  const signature = await wallet.signTypedData(
    unsignedTx.domain, 
    unsignedTx.types, 
    unsignedTx.action
  );
  
  const signedTx = {
    action: unsignedTx.action,
    nonce: unsignedTx.nonce,
    signature: {
      r: "0x" + signature.slice(2, 66),
      s: "0x" + signature.slice(66, 130),
      v: parseInt(signature.slice(130, 132), 16)
    }
  };
  
  const signedTransaction = btoa(JSON.stringify(signedTx));
  
  // Step 3: Broadcast the transaction
  const broadcastResponse = await fetch('https://staking.luganodes.com/hyperliquid/mainnet/api/v1/staking/broadcast', {
    method: 'POST',
    headers: {
      'api-key': 'your-api-key',
      'content-type': 'application/json'
    },
    body: JSON.stringify({
      signedTransaction: signedTransaction
    })
  });
  
  const broadcastData = await broadcastResponse.json();
  return broadcastData;
}
```

***


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.luganodes.com/apis/staking-apis-v2/hyperliquid/broadcast.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
