collection offer returns: request failed {"errors":["Asset does not exist."]}
trying to get this to work for more then a week now keep getting the same error request failed {"errors":["Asset does not exist."]}
here all the code i just removed the wallet private key and opensea api key
main.js:
const lookup = require("dns");
const buildOffer = require("./buildOffer");
const postOffer = require("./postOffer");
const signOffer = require("./signOffer");
const price =String(1000000000000000000*0.01);
const collectionSlug ="proof-moonbirds";
function delay(ms) {
return new Promise(resolve => setTimeout(resolve, ms))
}
var offer= buildOffer.buildOffer({
collectionSlug,
quantity: 1,
priceWei: BigInt(price),
creatorBasisPoints: BigInt(500),
creatorFeeRecipient: "0xc8a5592031f93debea5d9e67a396944ee01bb2ca",
expirationSeconds: BigInt(901),
}) .then(async offer => {
await delay(2000)
return { offer, signature: await signOffer.signOffer(offer) }
console.log(offer)
}).then((payload => postOffer.postOffer(collectionSlug, payload.offer, payload.signature).then(
response => {
console.log(`Offer posted! Order Hash: ${response.order_hash}`)
},
error => {
console.error("request failed")
console.error(JSON.stringify(error.response.data))
},
)
)
)
apiClient.js:
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.apiClient = void 0;
const axios_1 = __importDefault(require("axios"));
/*
export const apiClient = axios.create({
baseURL: "https://testnets-api.opensea.io/api/",
})
*/
exports.apiClient = axios_1.default.create({
baseURL: "https://api.opensea.io/api/",
headers: {
"X-API-KEY": "my api key"
}
});
buildOffer.js:
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildOffer = void 0;
const apiClient_1 = require("./apiClient");
const wallet_1 = require("./wallet");
const wethAddress = "0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6";
const openSeaFeeRecipient = "0x0000a26b00c1F0DF003000390027140000fAa719";
//const zone = "0x00000000e88fe2628ebc5da81d2b3cead633e89e"
const zone = "0x004c00500000ad104d7dbd00e3ae0a5c00560c00";
const zoneHash = "0x3000000000000000000000000000000000000000000000000000000000000000";
const conduitKey = "0x0000007b02230091a7ed01230072f7006a004d60a8d4e71d599b8104250f0000";
const getOfferer = () => {
const wallet = (0, wallet_1.getWallet)();
return wallet.address;
};
const getOffer = (priceWei) => {
return [
{
itemType: "1",
token: wethAddress,
identifierOrCriteria: 0,
startAmount: priceWei.toString(),
endAmount: priceWei.toString(),
},
];
};
const getPlatformFee = (priceWei) => {
const feeBasisPoints = BigInt(250);
const fee = (priceWei * feeBasisPoints) / BigInt(10000);
return {
itemType: 1,
token: wethAddress,
identifierOrCriteria: 0,
startAmount: fee.toString(),
endAmount: fee.toString(),
recipient: openSeaFeeRecipient, // OS Recipient
};
};
const getCreatorFee = (priceWei, basisPoints, receipient) => {
const fee = (priceWei * basisPoints) / BigInt(10000);
return {
itemType: 1,
token: wethAddress,
identifierOrCriteria: 0,
startAmount: fee.toString(),
endAmount: fee.toString(),
recipient: receipient,
};
};
const getTokenConsideration = async (collectionSlug, quantity) => {
const offerer = getOfferer();
const response = await apiClient_1.apiClient.post("v2/offers/build", {
offerer,
quantity,
criteria: {
collection: {
slug: collectionSlug,
},
},
});
return response.data.partialParameters.consideration[0];
};
const getConsideration = async (collectionSlug, quantity, priceWei, creatorBasisPoints, creatorFeeRecipient) => {
return [
await getTokenConsideration(collectionSlug, quantity),
getPlatformFee(priceWei),
getCreatorFee(priceWei, creatorBasisPoints, creatorFeeRecipient),
];
};
const getSalt = () => {
return Math.floor(Math.random() * 100000).toString();
};
const buildOffer = async (offerSpecification) => {
const { collectionSlug, quantity, priceWei, creatorBasisPoints, creatorFeeRecipient, expirationSeconds, } = offerSpecification;
const now = BigInt(Math.floor(Date.now() / 1000));
const startTime = now.toString();
const endTime = (now + expirationSeconds).toString();
const consideration = await getConsideration(collectionSlug, quantity, priceWei, creatorBasisPoints, creatorFeeRecipient);
const offer = {
offerer: getOfferer(),
offer: getOffer(priceWei),
consideration,
startTime,
endTime,
orderType: 2,
zone,
zoneHash,
salt: getSalt(),
conduitKey,
totalOriginalConsiderationItems: consideration.length.toString(),
counter: 0,
};
// console.log(offer);
return offer;
};
exports.buildOffer = buildOffer;
createWallet.js:
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const crypto_1 = __importDefault(require("crypto"));
const ethers_1 = require("ethers");
const id = crypto_1.default.randomBytes(32).toString("hex");
const privateKey = "0x" + id;
console.log("SAVE BUT DO NOT SHARE THIS:", privateKey);
const wallet = new ethers_1.Wallet(privateKey);
console.log("Address: " + wallet.address);
console.log("Add the above address to your .env file as WALLET_PRIVATE_KEY. e.g.");
console.log("WALLET_PRIVATE_KEY=" + privateKey);
postOffer.js:
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.postOffer = void 0;
const apiClient_1 = require("./apiClient");
const getCriteria = (collectionSlug) => {
return {
collection: {
slug: collectionSlug,
},
};
};
const postOffer = async (collectionSlug, offer, signature) => {
const payload = {
criteria: getCriteria(collectionSlug),
protocol_data: {
parameters: offer,
signature,
},
};
console.log("payload: %j", payload);
const response = await apiClient_1.apiClient.post("v2/offers", payload);
return response.data;
};
exports.postOffer = postOffer;
signOffer.js:
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.signOffer = void 0;
const wallet_1 = require("./wallet");
const types = {
// EIP712Domain: [
// {
// name: "name",
// type: "string",
// },
// {
// name: "version",
// type: "string",
// },
// {
// name: "chainId",
// type: "uint256",
// },
// {
// name: "verifyingContract",
// type: "address",
// },
// ],
OrderComponents: [
{
name: "offerer",
type: "address",
},
{
name: "zone",
type: "address",
},
{
name: "offer",
type: "OfferItem[]",
},
{
name: "consideration",
type: "ConsiderationItem[]",
},
{
name: "orderType",
type: "uint8",
},
{
name: "startTime",
type: "uint256",
},
{
name: "endTime",
type: "uint256",
},
{
name: "zoneHash",
type: "bytes32",
},
{
name: "salt",
type: "uint256",
},
{
name: "conduitKey",
type: "bytes32",
},
{
name: "counter",
type: "uint256",
},
],
OfferItem: [
{
name: "itemType",
type: "uint8",
},
{
name: "token",
type: "address",
},
{
name: "identifierOrCriteria",
type: "uint256",
},
{
name: "startAmount",
type: "uint256",
},
{
name: "endAmount",
type: "uint256",
},
],
ConsiderationItem: [
{
name: "itemType",
type: "uint8",
},
{
name: "token",
type: "address",
},
{
name: "identifierOrCriteria",
type: "uint256",
},
{
name: "startAmount",
type: "uint256",
},
{
name: "endAmount",
type: "uint256",
},
{
name: "recipient",
type: "address",
},
],
};
// chainid to 1 for main 5 for testnet
const domain = {
name: "Seaport",
version: "1.1",
chainId: "1",
verifyingContract: "0x00000000006c3852cbEf3e08E8dF289169EdE581",
};
const signOffer = async (offer) => {
const wallet = (0, wallet_1.getWallet)();
return await wallet._signTypedData(domain, types, offer);
};
exports.signOffer = signOffer;
wallet.js:
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getWallet = void 0;
const ethers_1 = require("ethers");
const getWallet = () => {
const privateKey = 'metamask privatekey';
if (privateKey === undefined) {
throw new Error("No private key found in .env");
}
return new ethers_1.Wallet(privateKey);
};
exports.getWallet = getWallet;
the payload that being send to V2/offers:
payload: {
"criteria": {
"collection": {
"slug": "proof-moonbirds"
}
},
"protocol_data": {
"parameters": {
"offerer": "0xe2a09Be09618b627ae8ac041092089684D033748",
"offer": [
{
"itemType": "1",
"token": "0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6",
"identifierOrCriteria": 0,
"startAmount": "10000000000000000",
"endAmount": "10000000000000000"
}
],
"consideration": [
{
"itemType": 4,
"token": "0x23581767a106ae21c074b2276d25e5c3e136a68b",
"identifierOrCriteria": "82735547737813269069975931296916280754442865570216943118540809611409490592441",
"startAmount": "1",
"endAmount": "1",
"recipient": "0xe2a09Be09618b627ae8ac041092089684D033748"
},
{
"itemType": 1,
"token": "0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6",
"identifierOrCriteria": 0,
"startAmount": "250000000000000",
"endAmount": "250000000000000",
"recipient": "0x0000a26b00c1F0DF003000390027140000fAa719"
},
{
"itemType": 1,
"token": "0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6",
"identifierOrCriteria": 0,
"startAmount": "500000000000000",
"endAmount": "500000000000000",
"recipient": "0xc8a5592031f93debea5d9e67a396944ee01bb2ca"
}
],
"startTime": "1669322835",
"endTime": "1669323736",
"orderType": 2,
"zone": "0x004c00500000ad104d7dbd00e3ae0a5c00560c00",
"zoneHash": "0x3000000000000000000000000000000000000000000000000000000000000000",
"salt": "45359",
"conduitKey": "0x0000007b02230091a7ed01230072f7006a004d60a8d4e71d599b8104250f0000",
"totalOriginalConsiderationItems": "3",
"counter": 0
},
"signature": " XXXXX"
}
}
Hi did you finally succeed ?
Hello, I have the same issue. Did you solve in some way?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions. If you believe this was a mistake, please comment.
Hey anyone any luck on this?