3️⃣API Examples
Before integrating, ensure you have:
✅ A wallet that supports the target blockchain (Base, Polygon, Avalanche, or Solana)
✅ USDC tokens for API payments (if required by the endpoint)
✅ An HTTP client library (axios, fetch, etc.)
✅ Web3 library for transaction signing (ethers.js, web3.js, or @solana/web3.js)
Integration Steps
Step 1: Send Initial Query
Send a POST request with your natural language command:
const response = await fetch("http://api.hashhunter.app/api/process", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
messages: [
{
role: "user",
content: "Send 10 USDC to 0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb",
},
],
wallet: "0xYourWalletAddress",
chain: "base",
}),
});
const data = await response.json();
console.log(data.operationId); // Save this for next stepsResponse:
{
"status": "success",
"operationId": "clxxx123456789",
"message": "Transaction prepared",
"requiresPayment": true
}Step 2: Request Payment Information
Using the operationId from Step 1, request payment details:
const paymentResponse = await fetch(
"http://api.hashhunter.app/api/process",
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
operationId: "clxxx123456789",
}),
}
);
const paymentData = await paymentResponse.json();
console.log(paymentData); // Contains X402 payment configurationResponse (402 Payment Required):
{
"x402Version": 1,
"error": "Token payment required",
"accepts": [
{
"scheme": "exact",
"network": "base",
"resource": "http://api.hashhunter.app/api/process",
"payTo": "0x5bc818f625cad773d35c6b81e944cc820a00bfc0",
"asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
"maxAmountRequired": "0",
"maxTimeoutSeconds": 300
}
],
"operationId": "clxxx123456789"
}Step 3: Make Payment (X402 Protocol)
Generate the X402 payment proof. This typically involves:
Creating a payment transaction to the
payToaddressIncluding the required metadata
Signing with your wallet
Generating the payment proof string
Note: The X402 payment implementation depends on your client library. Refer to X402 Documentation for detailed implementation.
Step 4: Verify Payment & Get Transaction
Send the payment proof to retrieve your transaction:
const txResponse = await fetch("http://api.hashhunter.app/api/process", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-PAYMENT": paymentProof, // Payment proof from Step 3
},
body: JSON.stringify({
operationId: "clxxx123456789",
}),
});
const txData = await txResponse.json();
console.log(txData.transactions); // Ready to executeResponse:
{
"status": "success",
"message": "Payment verified. Transaction ready for execution.",
"operationId": "clxxx123456789",
"transactions": [
{
"type": "evm",
"data": {
"to": "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb",
"data": "0xa9059cbb...",
"value": "0",
"chainId": 8453
}
}
]
}Step 5: Execute Transaction
Execute the transaction using your Web3 library:
For EVM Chains (Base, Polygon, Avalanche)
import { ethers } from "ethers";
// Connect to wallet
const provider = new ethers.providers.Web3Provider(window.ethereum);
const signer = provider.getSigner();
// Get transaction from API response
const tx = txData.transactions[0].data;
// Send transaction
const txResponse = await signer.sendTransaction({
to: tx.to,
data: tx.data,
value: tx.value,
chainId: tx.chainId,
});
// Wait for confirmation
const receipt = await txResponse.wait();
console.log("Transaction confirmed:", receipt.transactionHash);For Solana
import { Connection, Transaction } from "@solana/web3.js";
// Connect to Solana
const connection = new Connection("https://api.mainnet-beta.solana.com");
// Get transaction from API response
const serializedTx = txData.transactions[0].data;
// Deserialize and send
const transaction = Transaction.from(Buffer.from(serializedTx, "base64"));
const signature = await wallet.sendTransaction(transaction, connection);
// Wait for confirmation
await connection.confirmTransaction(signature);
console.log("Transaction confirmed:", signature);
Last updated