🥜
DangerAcorn Docs
  • DangerAcorn
    • Welcome
  • ACORN API
    • Get Started
      • Request an API Key
      • View API Plans
  • API STATUS
    • Tron - 🟡
    • Solana - 🚧
    • Ethereum - 🚧
  • Tron Network
    • Dedicated Nodes
    • SunPump API
      • Trade API
        • Local Trade API
      • Get Data
        • Get Quote
        • Get Token Details
        • Get Token Holders
        • Get Recent Trades
        • Get Token Balance
        • 🚧Webhooks
          • Subscriptions
    • Helpers
      • Create Wallet
      • Transfer
      • Approve Tokens
      • Check Allowance
      • 🚧Webhooks
        • Subscriptions
  • Solana Network
    • PumpFun API
      • Trade API
        • Live Trade API
        • Local Trade API
      • Get Data
        • Get Token Details
        • Get Token Holders
        • Get Recent Trades
        • 🚧Get Curve Progress
        • Get Token Price
        • 🚧Webhooks
          • Subscriptions
    • Helpers
      • Create Wallet
      • Transfer
      • Webhooks
        • Subscriptions
  • Socials
    • Discord
    • Telegram
Powered by GitBook
On this page
  • Endpoint
  • Parameters
  • Example Buy Request
  • Example Sell Request
  • Example Response JSON
  • Error Responses
  • Notes

Was this helpful?

  1. Tron Network
  2. SunPump API
  3. Trade API

Local Trade API

This API allows users to trade SunPump tokens without passing a private key or sensitive information. It works by building transaction instructions for local signing and broadcasting instead.

SunPump Trade Code Example - JS/TS
import TronWeb from 'tronweb';
import axios from 'axios';
import dotenv from 'dotenv';

dotenv.config();

const privateKey = process.env.PRIVATE_KEY || 'YOUR-TRON-PRIVATE-KEY'; // Your Private Key Hex
const tronWeb = new TronWeb({
  fullHost: 'YOUR_RPC_ENDPOINT', // you can use https://api.trongrid.io 
  privateKey,
});

export const sendLocalTradeRequest = async () => {
  try {
    console.log('Requesting unsigned transaction...');
    const userAddress = tronWeb.defaultAddress.base58;

    const response = await axios.post(
      'https://api.dangeracorn.com/sunpump/localTrade',
      {
        action: "buy", // Use "buy" or "purchase" for buying tokens | Use "sell" or "sale" when selling
        tokenAddress: "token-contract-address", // Token Contract Address in Base58 Format
        amount: "100%", // Amount of TRX to buy | Token Amount or % if Selling (ex. 1000000 = SELL 1,000,000 TOKENS) 
        slippage: "1", // Slippage % in whole number (1 = 1% Slippage)
        userAddress: "your-address" // Signer's public key in Base58 Format
      },
      {
        headers: {
          'Content-Type': 'application/json',
          'api-key': 'your-api-key' // If you don't have you you can get one at https://t.me/+pE-h-2eMeoRhZDBh
        }
      }
    );

    const { unsignedTx } = response.data;

    if (unsignedTx) {
      console.log('Raw transaction:', unsignedTx);

      // Step 3: Sign the transaction 
      console.log('Signing the transaction...');
      const signedTx = await tronWeb.trx.sign(unsignedTx);

      // Step 4: Broadcast the transaction 
      console.log('Broadcasting the signed transaction...');
      const broadcastResponse = await tronWeb.trx.sendRawTransaction(signedTx);

      if (broadcastResponse.result) {
        console.log('Transaction broadcasted successfully:', 'https://tronscan.org/#/transaction/' + broadcastResponse.txid);
      } else {
        console.log('Failed to broadcast the transaction:', broadcastResponse);
      }
    } else {
      console.log('Error: No unsigned transaction returned.');
    }
  } catch (error) {
    console.error('Error during the local trade request or broadcasting:', error);
  }
};

Endpoint

  • URL: /sunpump/localTrade

  • Method: POST

  • Content-Type: application/json

  • API Key Header: api-key: your-api-key-here

Parameters

Parameter
Type
Required
Description

type

string

Yes

Type of transaction: buy or sell.

tokenAddress

string

Yes

Token Contract Address

amount

number/string

Yes

Amount to trade (in TRX for tokens (or %) for sale).

userAddress

string

Yes

Public Tron Address of sender

slippage

number

No

Max allowed price change before the transaction is reverted

Example Buy Request

curl -X POST https://api.dangeracorn.com/sunpump/localTrade \
-H "Content-Type: application/json" \
-H "api-key: your-api-key" \
-d '{
  "action": "buy",
  "tokenAddress": "token-contract-address",
  "amount": 100,
  "slippage": 1,
  "userAddress": "sender-public-tron-address"
}'
npm install axios
const axios = require('axios');

const buyRequest = async () => {
  const response = await axios.post('https://api.dangeracorn.com/sunpump/localTrade', {
    action: 'buy',
    tokenAddress: 'token-contract-address',
    amount: 100, // Amount in TRX when buying
    slippage: 1,
    userAddress: 'sender-public-tron-address'
  }, {
    headers: {
      'Content-Type': 'application/json',
      'api-key': 'your-api-key'
    }
  });

  console.log(response.json());
};

buyRequest();
pip install requests
import requests

url = 'https://api.dangeracorn.com/sunpump/localTrade'
headers = {
    'Content-Type': 'application/json',
    'api-key': 'your-api-key'
}

data = {
    "action": "buy",
    "tokenAddress": "token-contract-address",
    "amount": 100,
    "slippage": 1,
    "userAddress": "sender-public-tron-address"
}

response = requests.post(url, json=data, headers=headers)
print(response.json())
npm install node-fetch
const fetch = require('node-fetch');

const buyRequest = async () => {
  const response = await fetch('https://api.dangeracorn.com/sunpump/localTrade', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'api-key': 'your-api-key'
    },
    body: JSON.stringify({
      action: 'buy',
      tokenAddress: 'token-contract-address',
      amount: 100,
      slippage: 1,
      userAddress: 'sender-public-tron-address'
    })
  });

  const data = await response.json();
  console.log(data);
};

buyRequest();
package main

import (
	"bytes"
	"encoding/json"
	"net/http"
	"fmt"
)

func main() {
	data := map[string]interface{}{
		"action": "buy",
		"tokenAddress": "token-contract-address",
		"amount": 100,
		"slippage": 1,
		"userAddress": "sender-public-tron-address",
	}

	payload, _ := json.Marshal(data)
	req, _ := http.NewRequest("POST", "https://api.dangeracorn.com/sunpump/localTrade", bytes.NewBuffer(payload))
	req.Header.Set("Content-Type", "application/json")
	req.Header.Set("api-key", "your-api-key")

	client := &http.Client{}
	resp, _ := client.Do(req)
	defer resp.Body.Close()

	fmt.Println("Response Status:", resp.Status)
}
<?php

$url = 'https://api.dangeracorn.com/sunpump/localTrade';

$data = array(
    'action' => 'buy',
    'tokenAddress' => 'token-contract-address',
    'amount' => 100,
    'slippage' => 1,
    'userAddress' => 'sender-public-tron-address'
);

$options = array(
    'http' => array(
        'header'  => "Content-Type: application/json\r\n" .
                     "api-key: your-api-key\r\n",
        'method'  => 'POST',
        'content' => json_encode($data),
    ),
);

$context  = stream_context_create($options);
$response = file_get_contents($url, false, $context);

echo $response;

Example Sell Request

curl -X POST https://api.dangeracorn.com/sunpump/localTrade \
-H "Content-Type: application/json" \
-H "api-key: your-api-key" \
-d '{
  "action": "sell",
  "tokenAddress": "token-contract-address",
  "amount": "50%",
  "slippage": 2,
  "userAddress": "sender-public-tron-address"
}'
npm install axios
const axios = require('axios');

const sellRequest = async () => {
  const response = await axios.post('https://api.dangeracorn.com/sunpump/localTrade', {
    action: 'sell',
    tokenAddress: 'token-contract-address',
    amount: '50%', // You may also use token amount as a number instead
    slippage: 2,
    userAddress: 'sender-public-tron-address'
  }, {
    headers: {
      'Content-Type': 'application/json',
      'api-key': 'your-api-key'
    }
  });

  console.log(response.data);
};

sellRequest();
pip install requests
import requests

url = 'https://api.dangeracorn.com/sunpump/localTrade'
headers = {
    'Content-Type': 'application/json',
    'api-key': 'your-api-key'
}

data = {
    "action": "sell",
    "tokenAddress": "token-contract-address",
    "amount": "50%",
    "slippage": 2,
    "userAddress": "sender-public-tron-address"
}

response = requests.post(url, json=data, headers=headers)
print(response.json())
npm install node-fetch
const fetch = require('node-fetch');

const sellRequest = async () => {
  const response = await fetch('https://api.dangeracorn.com/sunpump/localTrade', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'api-key': 'your-api-key'
    },
    body: JSON.stringify({
      action: 'sell',
      tokenAddress: 'token-contract-address',
      amount: '50%',
      slippage: 2,
      userAddress: 'sender-public-tron-address'
    })
  });

  const data = await response.json();
  console.log(data);
};

sellRequest();
package main

import (
	"bytes"
	"encoding/json"
	"net/http"
	"fmt"
)

func main() {
	data := map[string]interface{}{
		"action": "sell",
		"tokenAddress": "token-contract-address",
		"amount": "50%",
		"slippage": 2,
		"userAddress": "sender-public-tron-address",
	}

	payload, _ := json.Marshal(data)
	req, _ := http.NewRequest("POST", "https://api.dangeracorn.com/sunpump/localTrade", bytes.NewBuffer(payload))
	req.Header.Set("Content-Type", "application/json")
	req.Header.Set("api-key", "your-api-key")

	client := &http.Client{}
	resp, _ := client.Do(req)
	defer resp.Body.Close()

	fmt.Println("Response Status:", resp.Status)
}
<?php

$url = 'https://api.dangeracorn.com/sunpump/localTrade';

$data = array(
    'action' => 'sell',
    'tokenAddress' => 'token-contract-address',
    'amount' => '50%',
    'slippage' => 2,
    'userAddress' => 'sender-public-tron-address'
);

$options = array(
    'http' => array(
        'header'  => "Content-Type: application/json\r\n" .
                     "api-key: your-api-key\r\n",
        'method'  => 'POST',
        'content' => json_encode($data),
    ),
);

$context  = stream_context_create($options);
$response = file_get_contents($url, false, $context);

echo $response;

Example Response JSON

{
  "unsignedTx": {
    "raw_data": { /* transaction data */ },
    "txID": "b69f27c7bfcf54a464294f1df99aaeff1b53714a12a80460709b20923a24486c"
  },
  "status": "unsigned",
  "code": "200"
}

Error Responses

Invalid Parameters

{
  "error": "Invalid parameters",
  "message": "You must provide type, tokenAddress, amount, and userAddress",
  "code": "400"
}

Max Slippage Reached

{
  "error": "Simulation failed",
  "message": "Max slippage reached. Transaction reverted.",
  "code": "500"
}

Insufficient Funds

{
  "error": "Insufficient funds",
  "message": "Your account does not have enough funds to perform this transaction.",
  "code": "400"
}

Invalid Type

{
  "error": "Invalid type",
  "message": "Type must be either 'buy' or 'sell'.",
  "code": "400"
}

Notes

  • Rate Limiting: This endpoint is rate-limited according to your plan's API key limits. Ensure that you handle these limits in your application.

  • Unsigned Transactions: The API returns unsigned transactions that users must sign before broadcasting.

  • Slippage Tolerance: Ensure the slippage is reasonable to avoid reverted transactions.

PreviousTrade APINextGet Data

Last updated 9 months ago

Was this helpful?

Fees: A small fee is applied on each trade. Please refer to to see what fee your plan uses.

Plans