For education only: NFT bots for your Wallet
So I had this friend who was pretty upset because every time he wanted to do an offer on Opensea a bot took it , and as you could imagine it was "blazing fast".
Which made me think, as someone who do computers for a living, how to make an NFT bot which makes offers and buys NFTs in real time?
Well I dont know much about NFTs, but I love programming crasy experiments, so I decided to use NodeJs and ask the AIs how to do it, to be fair vibe coding but a story to tell.
So I started by looking into ChatGPT , which sugested some alternatives but not a direct script, you know it seems like it learned to just give hints on crypto stuff.
Then I asked DeepSeek which was way more efficient on code and an actual division of buying and offering.
Well what did I found ?
First is the Ethers library which is a library to manage
etherium and ilk
, which means the way you create a wallet instance
this.provider = new ethers.providers.JsonRpcProvider(infuraUrl);
this.wallet = new ethers.Wallet(privateKey, this.provider);
But also it helps to create contracts like this:
const wethContract = new ethers.Contract(
WETH_ADDRESS,
['function deposit() payable', 'function balanceOf(address) view returns (uint)'],
this.wallet
);
Then , there is Seaport JS , which is a library that wraps the seaport protocol for buying and selling NFTs
this.seaport = new Seaport(this.wallet, { overrides: { contractAddress: SEAPORT_ADDRESS } });
Which basically does all the creation of orders, the fulfilments allowances , which are key to create offers and buying , which then can be posted on OpenSea platform by REST
How the program would do offers and buy NFTs ?
Lets start with a disclaimer , There are many ways to do this and I am going to use the easiest one , and to be clear the best way to do this is by using a web-socket to Seaport, more direct, faster and you could be the one bot getting the first offers or buying the first one always(race conditions with the other 1k bots around).
Well in this program we would do an infinit loop which will:
1) fetch new lsitings
2) check prices for each listing ,
3) if the listing's price is smaller than a certain threshold it will buy it.
4) otherwhise it will make an offer.
while (true) {
try {
const listings = await this.fetchNewListings(collectionSlug);
for (const listing of listings) {
if (!listing.asset) continue;
const tokenId = listing.asset.token_id;
const contract = listing.asset.asset_contract.address;
const price = parseFloat(
ethers.utils.formatEther(
listing.ending_price
));
console.log(`🔍 Found NFT #${tokenId} for ${price} ETH`);
if (price < this.config.buyThreshold) {
const result = await this.buyNow(
contract,
tokenId,
price);
if (result?.txHash) {
console.log(`🛒 Bought NFT! TX: https://etherscan.io/tx/${result.txHash}`);
}
}
else {
// Make an offer (percentage of listing)
const offerPrice = price * this.config.offerPercentage;
const result = await this.makeOffer(
contract,
tokenId,
offerPrice);
if (result?.orderHash) {
console.log(`🤝 Offer made! View: https://opensea.io/assets/ethereum/${contract}/${tokenId}`);
}
}
}
await this.delay(this.config.pollingInterval);
}
catch (error) {
console.error(`Monitoring error:`, error.message);
await this.delay(this.config.errorRetryDelay);
}
}
If you want to check the whole result check my Github , give me sugestions , I am just doing it for fun really
Comments
Post a Comment