Offer on an NFT
Prerequisites
You should have already completed Part 1: Setup where you created all necessary keys and cloned our sample repo that uses the OpenSea SDK.
Find a NFT to offer on
First, you'll need to find the NFT you want to make an offer on. Go to OpenSea and browse around to find one you're interested in. At the time of writing this article, PUNKBITS is the number one trending collection on OpenSea, so let's use that for the remainder of the tutorial. Specifically, let's place an offer on PUNKBITS #6764. For this particular NFT, the contractAddress
and tokenId
are as follows:
contractAddress
:0x43fa8aeb7eaa2bb74cf1d07281ebebb76a23941c
tokenId
:6764
You'll need these parameters in the next few sections!
Update the code
Open up the [createOffer.ts](https://github.com/ProjectOpenSea/buy-sell-opensea-sdk-demo/blob/main/src/createOffer.ts)
file under the /src
directory. Here's the code:
import { WALLET_ADDRESS, sdk} from './utils/constants';
const createOffer = async () => {
// TODO: Fill in the token address and token ID of the NFT you want to make an offer on
let tokenAddress: string = "";
let tokenId: string = "";
let offerAmount: string = "";
const offer = {
accountAddress: WALLET_ADDRESS,
startAmount: offerAmount,
asset: {
tokenAddress: tokenAddress,
tokenId: tokenId,
},
};
try {
const response = await sdk.createOffer(offer);
console.log("Successfully created an offer with orderHash:", response.orderHash);
} catch (error) {
console.error("Error in createOffer:", error);
}
}
// Check if the module is the main entry point
if (require.main === module) {
// If yes, run the createOffer function
createOffer().catch((error) => {
console.error("Error in createOffer:", error);
});
}
export default createOffer;
Before running the script, you need to update Lines 6-8 (add values for tokenAddress
, tokenId
, and offerAmount
) to values that represent the NFT you want to offer on, and the price.
Create the offer
After setting the above variables, you'll need to first make sure the code compiles:
npm run build
Next, run the createOffer
script with this command:
npm run createOffer
If the offer was successfully created, you'll see this output from the script:
Successfully created an offer with orderHash: 0x12345928q98249834
Validate the offer
Navigate to the open offers tab in your Profile page, you'll see a tab that lists all of your open offers. If you successfully created the offer, it'll show up here. Here's an example from a script run:
Updated 10 months ago