---
updatedAt: 2025-09-22T22:24:41.000Z
agentTools:
  projectIndex: https://dev.tensor.trade/llms.txt
---

# Place a bid within 5% of Floor Price

```javascript JavaScript
const { Connection, Keypair, VersionedTransaction } = require("@solana/web3.js");

const path = require("path");
const fs = require("fs");

const SOLANA_RPC = process.env.SOLANA_RPC;
const COLLECTION_SLUG = process.env.COLLECTION_SLUG;
const TENSOR_API_KEY = process.env.TENSOR_API_KEY;

const walletPath = path.join(process.env.HOME, ".config", "solana", "id.json");
const walletData = fs.readFileSync(walletPath, "utf8");
let wallet = Keypair.fromSecretKey(Uint8Array.from(JSON.parse(walletData)));

const options = {
  method: "GET",
  headers: { accept: "application/json", "x-tensor-api-key": TENSOR_API_KEY },
};

const url = "https://api.mainnet.tensordev.io/api/v1/";

const queryParams = new URLSearchParams();
queryParams.append("sortBy", "statsV2.volume1h:desc");
queryParams.append("slugs", COLLECTION_SLUG);
queryParams.append("limit", 1);

const collectionsUrl = `${url}collections?${queryParams.toString()}`;

fetch(collectionsUrl, options)
  .then((response) => response.json())
  .then(async (response) => {
	  const connection = new Connection(SOLANA_RPC);
    const blockhash = await connection.getLatestBlockhash();
    return { response, blockhash };
  })
  .then(async ({ response, blockhash }) => {
    const floorPrice = response.collections[0].stats.buyNowPrice; // in Lamports
    const bidPrice = floorPrice - floorPrice * 0.05; // 5% below current floor price
    const bidParams = new URLSearchParams();

    bidParams.append("owner", wallet.publicKey.toString());
    bidParams.append("price", bidPrice);
    bidParams.append("quantity", 1);
    bidParams.append("slug", COLLECTION_SLUG);
    bidParams.append("blockhash", blockhash.blockhash);

    const bidURL = `${url}tx/collection_bid?${bidParams.toString()}`;

    const tx = await fetch(bidURL, options);
    return tx.json();
  })
  .then(async (response) => {
		const connection = new Connection(SOLANA_RPC);
    // Deserialize the transactions
    const txsToSign = response.txs.map((tx) =>
      tx.txV0
        ? VersionedTransaction.deserialize(response.txs[0].txV0.data)
        : Transaction.from(tx.tx.data)
    );
    // Sign the transactions
    txsToSign.map((tx) => tx.sign([wallet]));
    // Must send txs serially for a given response!
    for (const tx of txsToSign) {
      const sig = await connection.sendTransaction(tx);
      await connection.confirmTransaction(sig, { blockhash: "confirmed" });
      console.log(`Transaction confirmed. https://solscan.io/tx/${sig}`);
    }
  })
  .catch((err) => console.error(err));

```

# Setup Environment

<!-- javascript@1-4 -->

Install required libraries

```.shell
npm install @solana/web3.js
```

# Get Environment Variables

<!-- javascript@6-8 -->

Set constants with environment variables

# Load Solana Wallet

<!-- javascript@10-14 -->

Load the Solana wallet located at the solana-cli default location 

~/.config/solana/id.json

# Setup API Request

<!-- javascript@1-19 -->

Set your API request Headers, Parameters, and construct the full URL

# Fetch Collection Details

<!-- javascript@21-28 -->

Get the current floor price of the collection

# Parse the response to JSON

<!-- javascript@29 -->

Get the JSON of the response and pass it down

# Fetch Current Blockhash

<!-- javascript@30-34 -->

Using Solana Connection, fetch the Latest Blockhash, this is needed to construct the next Transaction request

# Fetch Bid Transaction

<!-- javascript@35-50 -->

With the responseData create a Bid NFT Transaction

# Deseralize Transaction

<!-- javascript@54-58 -->

Deserialize and parse the API response

# Sign Trasnactions

<!-- javascript@60 -->

Sign all transactions received from API

# Send Transactions

<!-- javascript@62-66 -->

Using Solana Connection, send the signed transactions to the network

# Run Code



With the recipe saved to a file set environment variables and run it

```shell
COLLECTION_SLUG=0O0O-1a2b-3c4d
TENSOR_API_KEY=0O0O-1a2b-3c4d
SOLANA_RPC=https://api.mainnet-beta.solana.com
node script.js
```