Broadcast
6. Send a transaction to the network
POST /api/v1/staking/broadcast
Broadcast a signed transaction to the Hyperliquid network.
Request Body
{
"signedTransaction": "eyJhY3Rpb24iOnsidHlwZSI6ImNEZXBvc2l0IiwiaHlwZXJsaXF1aWRDaGFpbiI6IlRlc3RuZXQiLCJzaWduYXR1cmVDaGFpbklkIjoiMHg2NmVlZSIsIndlaSI6MTUwMDAwMDAwLCJub25jZSI6MTcwNzEyMzQ1Njc4OX0sIm5vbmNlIjoxNzA3MTIzNDU2Nzg5LCJzaWduYXR1cmUiOnsiciI6IjB4MTIzNDU2Nzg5MGFiY2RlZi4uLiIsInMiOiIweGZlZGNiYTA5ODc2NTQzMjEuLi4iLCJ2IjoyN319"
}
Parameters
signedTransaction
(string, required): Base64 encoded signed transaction
Response
{
"result": {
"transactionHash": "0xabc123def456...",
"status": "success",
"createdAt": "2025-01-21T12:00:00.000Z"
}
}
cURL Example
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:
// 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
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;
}
Last updated