-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgoal.html
More file actions
167 lines (152 loc) · 6.58 KB
/
goal.html
File metadata and controls
167 lines (152 loc) · 6.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>OpenSea Listing Example</title>
<script src="https://cdn.jsdelivr.net/npm/ethers@5.6.9/dist/ethers.umd.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
</head>
<body>
<h1>Create Listing on OpenSea</h1>
<form id="listingForm">
<label for="tokenAddress">Token Address:</label>
<input type="text" id="tokenAddress" name="tokenAddress" required>
<br>
<label for="tokenId">Token ID:</label>
<input type="text" id="tokenId" name="tokenId" required>
<br>
<label for="listingAmount">Listing Amount (in ETH):</label>
<input type="text" id="listingAmount" name="listingAmount" required>
<br>
<button type="submit">Create Listing</button>
</form>
<script>
// Replace with your own Alchemy API key
const ALCHEMY_API_KEY = 'eG3jW0KFR0_DslPgFc011OnLfBLQvFME';
const provider = new ethers.providers.JsonRpcProvider(`https://eth-sepolia.g.alchemy.com/v2/${ALCHEMY_API_KEY}`, {
name: 'sepolia',
chainId: 11155111
});
document.getElementById('listingForm').addEventListener('submit', async (event) => {
event.preventDefault();
// Connect to MetaMask wallet
if (typeof window.ethereum !== 'undefined') {
try {
await window.ethereum.request({ method: 'eth_requestAccounts' });
const web3Provider = new ethers.providers.Web3Provider(window.ethereum, "any");
const signer = web3Provider.getSigner();
const tokenAddress = document.getElementById('tokenAddress').value;
const tokenId = document.getElementById('tokenId').value;
const listingAmount = document.getElementById('listingAmount').value;
// Ensure we're connected to Sepolia network (Sepolia has chainId 11155111)
const network = await web3Provider.getNetwork();
if (network.chainId !== 11155111) {
alert("Please connect to the Sepolia testnet.");
return;
}
// Get address directly from the signer, avoiding ENS resolution
const account = await signer.getAddress();
// Create listing data
const listingData = {
offerer: account,
offer: [
{
itemType: 2, // ERC721
token: tokenAddress,
identifierOrCriteria: tokenId,
startAmount: ethers.utils.parseUnits(listingAmount, "ether").toString(),
endAmount: ethers.utils.parseUnits(listingAmount, "ether").toString()
}
],
consideration: [
{
itemType: 0, // Native - Ether
token: ethers.constants.AddressZero,
identifierOrCriteria: 0,
startAmount: ethers.utils.parseUnits("0.025", "ether").toString(), // OpenSea Fee (2.5%)
endAmount: ethers.utils.parseUnits("0.025", "ether").toString(),
recipient: "0xOpenSeaFeeRecipientAddress" // OpenSea fee recipient
},
{
itemType: 2,
token: tokenAddress,
identifierOrCriteria: tokenId,
startAmount: ethers.utils.parseUnits(listingAmount, "ether").toString(),
endAmount: ethers.utils.parseUnits(listingAmount, "ether").toString(),
recipient: account
}
],
startTime: Math.floor(Date.now() / 1000),
endTime: Math.floor(Date.now() / 1000) + 86400, // 1 day later
orderType: 0,
zone: ethers.constants.AddressZero,
zoneHash: ethers.constants.HashZero,
salt: ethers.BigNumber.from(ethers.utils.randomBytes(32)).toString(),
conduitKey: "0x0000007b02230091a7ed01230072f7006a004d60a8d4e71d599b8104250f0000",
totalOriginalConsiderationItems: 2,
counter: 0
};
// Get the domain data for signing
const domain = {
name: 'OpenSea',
version: '1.6',
chainId: 11155111, // Sepolia Testnet chain ID
verifyingContract: "0x0000000000000068f116a894984e2db1123eb395" // OpenSea Seaport contract
};
// Get the types for the signature
const types = {
OrderComponents: [
{ name: 'offerer', type: 'address' },
{ name: 'offer', type: 'OfferItem[]' },
{ name: 'consideration', type: 'ConsiderationItem[]' },
{ name: 'startTime', type: 'uint256' },
{ name: 'endTime', type: 'uint256' },
{ name: 'orderType', type: 'uint8' },
{ name: 'zone', type: 'address' },
{ name: 'zoneHash', type: 'bytes32' },
{ name: 'salt', type: 'uint256' },
{ name: 'conduitKey', type: 'bytes32' },
{ name: 'totalOriginalConsiderationItems', type: 'uint256' },
{ 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' }
]
};
// Sign the listing data using EIP-712 typed data signing
const signature = await signer._signTypedData(domain, types, listingData);
// Make the API request to OpenSea, adding the signature to the request body
const response = await axios.post(
'https://api.opensea.io/api/v2/orders/sepolia/seaport/listings',
{ ...listingData, signature },
{
headers: {
'accept': 'application/json',
'content-type': 'application/json'
}
}
);
console.log("Listing created successfully:", response.data);
} catch (error) {
console.error("Error creating listing:", error);
}
} else {
console.error("MetaMask is not installed.");
}
});
</script>
</body>
</html>