Modifier légèrement ce code snippet Javascript sans rien m'expliquer en résolvant les…
- User
Modifier légèrement ce code snippet Javascript sans rien m'expliquer en résolvant les points suivants :
- Le paiement est unitaire en ETH de 0.1 ETH, réparti dans un seul champ consideration. Je veux deux consideration items 6. consideration (tuple[]): 6.1. itemType (uint8): 0 6.2. token (address): 0x0000000000000000000000000000000000000000 6.3. identifier (uint256): 0 6.4. amount (uint256): 99999000000000000 6.5. recipient (address): 0xB0077B904F9f5C9009FD2b90d2643Cf9E1632AB4 6. consideration (tuple[]): 6.1. itemType (uint8): 0 6.2. token (address): 0x0000000000000000000000000000000000000000 6.3. identifier (uint256): 0 6.4. amount (uint256): 1000000000000 6.5. recipient (address): 0x0000a26b00c1F0DF003000390027140000fAa719
- ce snippet structure l’ordre complet dans un paramètre parameters unique comme tuple imbriqué : je veux des paramètres légèrement différents dans le format des tuples imbriqués notamment un champ orderHash visible explicitement. En résumé je veux un orderHash transmis explicitement (car requis explicitement par la fonction/structure), je ne veux pas qu'il soit calculé implicitement en interne.
- je veux un Transfert direct sans conduit, je ne veux pas une Utilisation du conduit OpenSea standard
Code snippet Javascript à modifier :
(async () => { if (!window.ethereum) { alert("Please install MetaMask!"); return; }
async function loadEthers() { if (typeof ethers !== "undefined") return; return new Promise((resolve, reject) => { const script = document.createElement("script"); script.src = "https://cdn.jsdelivr.net/npm/ethers@5.7.2/dist/ethers.umd.min.js"; script.onload = () => { if (typeof ethers !== "undefined" || window.ethers) resolve(); else reject(new Error("ethers.js loaded but ethers variable not found")); }; script.onerror = () => reject(new Error("Failed to load ethers.js")); document.head.appendChild(script); }); }
try { await loadEthers(); } catch (error) { console.error(error); alert("Erreur critique : impossible de charger ethers.js."); return; }
try { await ethereum.request({ method: "eth_requestAccounts" });
const provider = new ethers.providers.Web3Provider(window.ethereum); const signer = provider.getSigner(); // --- CONFIG --- const offerer = "0xB0077B904F9f5C9009FD2b90d2643Cf9E1632AB4"; const seaportAddress = "0x00000000000000ADc04C56Bf30aC9d3c0aAF14dC"; const openSeaFees = "0x0000a26b00c1F0DF003000390027140000fAa719"; const nftAddress = "0xb99dc2f1ba4e9f152c1aadaac62c185b7305e019"; const tokenId = "1"; const priceWeiOffer = ethers.utils.parseEther("0.099999"); // 0.099999 ETH offer prix, en wei const priceWeiFee = ethers.utils.parseEther("0.000001"); // 0.000001 ETH fee prix const chainId = await signer.getChainId(); // --- Fixe startTime et endTime selon demande --- const fixedStartTime = "0"; const fixedEndTime = "2147483647"; // --- Salt dynamique --- const saltBytes = ethers.utils.randomBytes(32); const saltBN = ethers.BigNumber.from(saltBytes); const salt = saltBN.toString(); // --- Conduit Key --- const conduitKey = "0x0000000000000000000000000000000000000000000000000000000000000000"; const fulfillerConduitKey = "0x0000000000000000000000000000000000000000000000000000000000000000"; // --- Initialise contrat Seaport pour récupérer counter --- const seaportAbi = [ "function getCounter(address offerer) view returns (uint256)", ]; const seaportContract = new ethers.Contract(seaportAddress, seaportAbi, provider); const counterBN = await seaportContract.getCounter(offerer); const counter = counterBN.toString(); // --- Vérifier adresse signer (doit être offerer) --- const from = (await signer.getAddress()); if (from.toLowerCase() !== offerer.toLowerCase()) { alert(`Adresse connectée (${from}) différente de l'offerer (${offerer}), changez de compte MetaMask.`); return; } // --- Construire la structure EIP-712 complète --- const typedData = { types: { 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" }, ], }, primaryType: "OrderComponents", domain: { name: "Seaport", version: "1.5", chainId, verifyingContract: seaportAddress, }, message: { offerer, zone: "0x0000000000000000000000000000000000000000", offer: [ { itemType: 2, // ERC721 token: nftAddress, identifierOrCriteria: tokenId, startAmount: "1", endAmount: "1", }, ], consideration: [ { itemType: 0, // Ether token: "0x0000000000000000000000000000000000000000", identifierOrCriteria: "0", startAmount: priceWeiOffer.toString(), endAmount: priceWeiOffer.toString(), recipient: offerer, }, { itemType: 0, token: "0x0000000000000000000000000000000000000000", identifierOrCriteria: "0", startAmount: priceWeiFee.toString(), endAmount: priceWeiFee.toString(), recipient: openSeaFees, }, ], orderType: 2, // FULL_OPEN startTime: fixedStartTime, endTime: fixedEndTime, zoneHash: "0x0000000000000000000000000000000000000000000000000000000000000000", salt, conduitKey, counter, }, }; // --- Signer avec eth_signTypedData_v4 --- const signature = await window.ethereum.request({ method: "eth_signTypedData_v4", params: [from, JSON.stringify(typedData)], }); // --- Préparer advancedOrder pour fulfillAdvancedOrder --- const advancedOrder = { parameters: typedData.message, numerator: "1", denominator: "1", signature, extraData: "0x", }; const criteriaResolvers = []; const recipient = from; // --- Construire la chaîne parameters complète et dépliée comme demandé --- const offerItem = typedData.message.offer[0]; const consideration0 = typedData.message.consideration[0]; const consideration1 = typedData.message.consideration[1]; // total original consideration est somme des startAmount consideration let totalOriginalConsiderationItems = typedData.message.consideration.reduce((acc, ci) => { return acc.add(ethers.BigNumber.from(ci.startAmount)); }, ethers.BigNumber.from(0)); // Override totalOriginalConsiderationItems to 2 as requested totalOriginalConsiderationItems = ethers.BigNumber.from(2); const parametersArr = [ offerer, // adresse (respecter casse d’origine) typedData.message.zone, offerItem.itemType, offerItem.token, offerItem.identifierOrCriteria, offerItem.startAmount, offerItem.endAmount, consideration0.itemType, consideration0.token, consideration0.identifierOrCriteria, consideration0.startAmount, consideration0.endAmount, consideration0.recipient, consideration1.itemType, consideration1.token, consideration1.identifierOrCriteria, consideration1.startAmount, consideration1.endAmount, consideration1.recipient, typedData.message.orderType, fixedStartTime, fixedEndTime, typedData.message.zoneHash, typedData.message.salt, typedData.message.conduitKey, totalOriginalConsiderationItems.toString() ]; // *** AFFICHAGE *** console.log(".parameters (tuple) :", parametersArr.join(",")); console.log(".numerator (uint120) :", advancedOrder.numerator); console.log(".denominator (uint120) :", advancedOrder.denominator); console.log(".signature (bytes) :", advancedOrder.signature); console.log(".extraData (bytes) :", advancedOrder.extraData); console.log("fulfillerConduitKey (bytes32) :", fulfillerConduitKey); console.log("recipient (address) :", recipient); alert("Listing signé avec succès (ordre complet). Voir console pour les détails."); - Assistant
- User
- Assistant
- User
- Assistant
- User
Erreur lors de l'achat : Error: cannot estimate gas; transaction may fail or may require manual gas limit
- Assistant