-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfrontend.html
667 lines (597 loc) · 34.9 KB
/
frontend.html
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
<!DOCTYPE html>
<html>
<head>
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
<script>
// Address of the Onchain Marketplace contract, set automatically by the constructor during contract creation
const contractAddress = '0x989c1d25feF13B4972D1Ad33c1892f50bDc22950';
const seaport = '0x00000000000001ad428e4906aE43D8F9852d0dD6';
const openseaAddress = '0x0000a26b00c1F0DF003000390027140000fAa719';
const openseaFee = 25000000000000000/1e18;
const openseaConduitKey = '0x0000007b02230091a7ed01230072f7006a004d60a8d4e71d599b8104250f0000';
const defaultCollection = '0xa29926934846fbf1000b5bce7a309a89dfb6f05a';
let royalties, royaltyAddress, incRoyalties, incOpensea;
// Function to send requests to the user's wallet
const request = (method, params) => window.ethereum.request({ method, params });
// Functions to query and adjust page content during user/wallet interactions
const getHtml = (id) => document.getElementById(id);
const setHtml = (id, html) => document.getElementById(id).innerHTML = html;
const createHtml = (tag, options) => {
const element = document.createElement(tag);
for (const key in options) {
element[key] = options[key];
}
return element;
}
// Function to convert to hex number in string format
const toHex = (num) => BigInt(num).toString(16);
// Connect to a user's wallet, fetch the orders for sale in the collection and display them on the page, triggered by the 'Load collection' button
async function connect() {
// Connect to the user's wallet
try {
const accounts = await request('eth_requestAccounts');
setHtml('walletAddress', accounts[0]);
setHtml('welcome', 'Welcome ');
} catch (error) {
setHtml('txStatus', error);
}
// Switch wallet to Goerli
request('wallet_switchEthereumChain', [{ chainId: '0x5' }]);
// Check if the user is connected to Goerli
const networkVersion = await request('net_version');
if (networkVersion != 5) {
setHtml('txStatus', 'Please connect to the Goerli test network before you continue.');
return;
}
// Get the collection address to display
const token = (getHtml('tokenAddress').value.slice(2) || defaultCollection.toLowerCase().slice(2));
// Display loading message and select the parent element of all collection item
setHtml('txStatus', 'Loading...')
setHtml('forSale', '');
const container = getHtml('forSale');
// Check royalties
checkRoyalties(token);
// Get the list of tokens for sale in the collection
const tokenList = await request('eth_call',[{ to: contractAddress, data:'0x093376fe000000000000000000000000'+token }, 'latest'])
const countClean = parseInt(tokenList.substring(66,130), 10);
const ids = [];
// Loop through the list of tokens for sale
for(let i = 0; i < countClean; i++) {
const id = tokenList.substring(130 + i * 64, 130 + (i + 1) * 64);
const idClean = Number(parseInt(id, 16));
ids.push(idClean);
const token32 = "0".repeat(64-token.length)+token;
const idHex = toHex(idClean);
const id32 = "0".repeat(64-idHex.length)+idHex;
const data = '0xa80a3baa'+token32+id32;
// Check if the token is still for sale
const isActive = await request('eth_call',[{ to: contractAddress, data: data }, 'latest']);
if(isActive.substring(2,66) != '0'.repeat(64)) {
// Get the order details
const data = '0x793b8c6d000000000000000000000000'+token+id;
const orderData = await request('eth_call',[{ to: contractAddress, data:data }, 'latest']);
const endTime = Number(parseInt(orderData.substring(130,194), 16));
const endTimeDate = new Date(endTime * 1000);
const price = orderData.substring(2,66);
// Get the token URI
const dataURI = '0xc87b56dd'+id32;
const rawURI = await request('eth_call',[{ to: '0x'+token, data: dataURI }, 'latest']);
const URI = await decodeTokenURI(rawURI);
const image = URI.image;
const name = (URI.name || idClean);
// Create a new tile for the token and append it to the parent element
const newItem = createHtml('div', { id: idClean, className: 'tiles', style: 'position: relative;' });
container.appendChild(newItem);
if (image) {
newItem.appendChild(createHtml('img', { src: image, style: 'max-height: 30vh; max-width: 45vw;', onclick: () => detailPopUp(id32,token,'media'), className: 'click' }));
}
const itemTitle = createHtml('p', { style: 'font-weight: bold; font-size: 0.85em; margin-bottom: -0.5vh; margin-top: 0.5vh; text-align: center; white-space: nowrap;' })
itemTitle.appendChild(createHtml('span', { innerHTML: name, onclick: () => detailPopUp(id32,token,'media'), className: 'click' }));
itemTitle.appendChild(createHtml('span', { innerHTML: ' 🛈', style: 'font-weight: lighter;', onclick: () => detailPopUp(id32,token,'attributes'), className: 'click' }));
newItem.append(
itemTitle,
createHtml('p', { innerHTML: `for sale until ${endTimeDate.toLocaleDateString()}`, style: 'font-weight: lighter; font-size: 0.7em; margin: 0px; margin-bottom: 0.5vh; text-align: center;', onclick: () => detailPopUp(id32,token,'media'), className: 'click' }),
);
const buyButton = createHtml('button', { style: 'padding: 0.6em 0.8em; font-size: 0.7em'});
const priceClean = ((Number(parseInt(price, 16))*(100+royalties)/100));
const priceWei = toHex(priceClean*1e3);
const priceWei32 = "0".repeat(64-priceWei.length)+priceWei;
buyButton.innerHTML = 'Buy now Ξ'+(priceClean/1e15).toFixed(3);
const account = getHtml('walletAddress').innerHTML.slice(2);
buyButton.onclick = () => {
buy('0x'+priceWei32, token, id, account);
};
newItem.appendChild(buyButton);
}
}
getHtml('sell').style = 'display: block;';
setHtml('txStatus', '')
}
// Check if the token for sale is approved for Seaport, if not approve it for Seaport. Then create and sign an order for the token and send it to the Onchain Marketplace contract.
async function sign(walletAddress,tokenAddress,tokenId,priceWei,startTime,endTime,salt,opensea) {
const seaportAddress = seaport.slice(2)
// Check if the token is approved for Seaport
const tokenIdBigInt = BigInt(tokenId).toString(16);
const idCalldata = '0'.repeat(64-tokenIdBigInt.length)+tokenIdBigInt;
const calldata = '0x081812fc'+idCalldata;
const result = await request('eth_call',[{ from: walletAddress, to: tokenAddress, data:calldata }, 'latest'])
// If not, approve it for Seaport
if(result.slice(-40) != seaportAddress.toLowerCase()) {
const calldata2 = '0x095ea7b3'+'0'.repeat(64-seaportAddress.length)+seaportAddress+idCalldata;
const tx = await request('eth_sendTransaction',[{ from: walletAddress, to: tokenAddress, data:calldata2 }]);
const receipt = await getTxReceipt(tx);
setHtml('txStatus', `Transaction ${tx} ${receipt.status ? 'was successful.' : 'failed.'}`);
}
// Get the counter for the address
const counter = await getCounter(walletAddress);
let openseaConsideration;
let royaltiesConsideration;
let os = false;
const royaltyPrice = priceWei*(royalties/100);
const openseaPrice = (priceWei+royaltyPrice)*openseaFee;
if(royalties > 0) {
royaltiesConsideration = {
'itemType': '0',
'token': '0x0000000000000000000000000000000000000000',
'identifierOrCriteria': '0',
'startAmount': String(royaltyPrice),
'endAmount': String(royaltyPrice),
'recipient': royaltyAddress
}
}
let considerations = royaltiesConsideration ? [royaltiesConsideration] : [];
// Order structure for EIP712 signing
let msgParams = createMsgParams(priceWei,walletAddress,tokenAddress,tokenId,startTime,endTime,salt,counter,considerations,os);
const signature = await request( 'eth_signTypedData_v4', [ walletAddress, msgParams ] );
let signatureOpensea = '0x';
if (opensea) {
openseaConsideration = {
'itemType': '0',
'token': '0x0000000000000000000000000000000000000000',
'identifierOrCriteria': '0',
'startAmount': String(openseaPrice),
'endAmount': String(openseaPrice),
'recipient': openseaAddress
}
considerations = [
...(openseaConsideration ? [openseaConsideration] : []),
...(royaltiesConsideration ? [royaltiesConsideration] : []),
];
os = true;
msgParams = createMsgParams(priceWei,walletAddress,tokenAddress,tokenId,startTime,endTime,salt,counter,considerations,os);
signatureOpensea = await request( 'eth_signTypedData_v4', [ walletAddress, msgParams ] );
}
// Sign the sell order
return [signature, signatureOpensea];
}
// Full sell process, triggered when the 'Sell' button is pressed
async function sell() {
setHtml('txStatus', '')
// Get the sell order parameters
const walletAddress = getHtml('walletAddress').textContent;
const tokenAddress = getHtml('tokenAddress').value;
const tokenId = getHtml('tokenId').value;
const price = getHtml('price').value;
const duration = getHtml('duration').value;
const opensea = getHtml('listOS').checked;
// Convert the parameters to the correct format
const priceWei = price * 1e18;
const durationSeconds = duration * 86400;
const startTime = Math.floor(Date.now() / 1000);
const endTime = Math.floor(Date.now() / 1000) + durationSeconds;
const salt = Math.floor(Math.random()*64999);
const startTimeBigInt = toHex(startTime);
const endTimeBigInt = toHex(endTime);
const saltBigInt = toHex(salt);
const priceWeiBigInt = toHex(priceWei);
const tokenIdBigInt = toHex(tokenId);
const royaltyPriceWeiBigInt = toHex(priceWei*(royalties/100))
// 32 bytes of zero and one, to compose the calldata
const zero = '0'.repeat(64);
const one = '0'.repeat(63)+'1';
let bytesTwo, bytesFour, totalConsiderations, considerationBytes;
if(royalties>0) {
bytesTwo = '0'.repeat(61)+'4c0'
bytesFour = '0'.repeat(61)+'400'
totalConsiderations = '0'.repeat(63)+'2';
const considerationBytesList = [
'0'.repeat(192),
'0'.repeat(64-priceWeiBigInt.length)+priceWeiBigInt,
'0'.repeat(64-priceWeiBigInt.length)+priceWeiBigInt,
'0'.repeat(24)+walletAddress.slice(2).toLowerCase(),
'0'.repeat(192),
'0'.repeat(64-royaltyPriceWeiBigInt.length)+royaltyPriceWeiBigInt,
'0'.repeat(64-royaltyPriceWeiBigInt.length)+royaltyPriceWeiBigInt,
'0'.repeat(24)+royaltyAddress.slice(2).toLowerCase()
]
considerationBytes = considerationBytesList.join('');
} else {
bytesTwo = '0'.repeat(61)+'400'
bytesFour = '0'.repeat(61)+'340'
totalConsiderations = '0'.repeat(63)+'1';
const considerationBytesList = [
'0'.repeat(192),
'0'.repeat(64-priceWeiBigInt.length)+priceWeiBigInt,
'0'.repeat(64-priceWeiBigInt.length)+priceWeiBigInt,
'0'.repeat(24)+walletAddress.slice(2).toLowerCase(),
]
considerationBytes = considerationBytesList.join('');
}
// Get the sell order signature
let [signature,signatureOpensea] = await sign(walletAddress,tokenAddress,tokenId,priceWei,startTime,endTime,salt,opensea);
if (signatureOpensea=='0x') {
signatureOpensea = zero;
} else {
signatureOpensea = '0'.repeat(62)+'41'+signatureOpensea.slice(2)+'0'.repeat(62)
}
// Compose the calldata (each segment is 32 bytes)
const calldataSegments = [
'0xe40abfcb',
'0'.repeat(62)+'40',
bytesTwo,
'0'.repeat(62)+'40',
bytesFour,
'0'.repeat(24)+walletAddress.slice(2).toLowerCase(),
'0'.repeat(24)+contractAddress.slice(2).toLowerCase(),
'0'.repeat(61)+'160',
'0'.repeat(61)+'220',
zero,
'0'.repeat(64-startTimeBigInt.length)+startTimeBigInt,
'0'.repeat(64-endTimeBigInt.length)+endTimeBigInt,
zero,
'0'.repeat(64-saltBigInt.length)+saltBigInt,
zero,
totalConsiderations,
one,
'0'.repeat(63)+'2',
'0'.repeat(24)+tokenAddress.slice(2).toLowerCase(),
'0'.repeat(64-tokenIdBigInt.length)+tokenIdBigInt,
one,
one,
totalConsiderations,
considerationBytes,
'0'.repeat(62)+'41'+signature.slice(2)+'0'.repeat(62),
signatureOpensea
]
// Join the calldata segments
const calldata = calldataSegments.join('');
// Send the transaction
const tx = await request('eth_sendTransaction', [{ from: walletAddress, to: contractAddress, data: calldata }]);
const receipt = await getTxReceipt(tx);
setHtml('txStatus', `Transaction ${tx} ${receipt.status ? 'was successful.' : 'failed.'}`);
}
// Function triggered when the 'Buy' button on an item tile is pressed
async function buy(amount,token,tokenId,recipient) {
setHtml('txStatus', '')
const walletAddress = getHtml('walletAddress').textContent;
// Compose calldata
const calldataSegments = [
'0xdb61c76e',
'0'.repeat(64-token.length)+token,
tokenId,
'0'.repeat(64-recipient.length)+recipient
]
// Join calldata segments
const calldata = calldataSegments.join('');
// Send the transaction
const tx = await request('eth_sendTransaction', [{ from: walletAddress, to: contractAddress, value: amount, data: calldata }]);
const receipt = await getTxReceipt(tx);
setHtml('txStatus', `Transaction ${tx} ${receipt.status ? 'was successful.' : 'failed.'}`);
}
async function cancel() {
setHtml('txStatus', '')
const walletAddress = getHtml('walletAddress').textContent;
const tokenAddress = getHtml('tokenAddress').value;
const tokenIdBigInt = toHex(getHtml('tokenIdCancel').value);
// Compose calldata
const calldataSegments = [
'0x6a206137',
'0'.repeat(24)+tokenAddress.slice(2).toLowerCase(),
'0'.repeat(64-tokenIdBigInt.length)+tokenIdBigInt
]
// Join calldata segments
const calldata = calldataSegments.join('');
// Send the transaction
const tx = await request('eth_sendTransaction', [{ from: walletAddress, to: contractAddress, data: calldata }]);
const receipt = await getTxReceipt(tx);
setHtml('txStatus', `Transaction ${tx} ${receipt.status ? 'was successful.' : 'failed.'}`);
}
async function getCounter(offerer) {
const calldata = "0xf07ec373"+'0'.repeat(24)+offerer.slice(2).toLowerCase();
const counter = await request('eth_call', [{ to: seaport, data: calldata }, 'latest']);
return counter;
}
async function getTxReceipt(tx) {
let txReturn = await request('eth_getTransactionReceipt', [tx]);
while(txReturn == null){
txReturn = await request('eth_getTransactionReceipt', [tx]);
setHtml('txStatus',`Transaction ${tx} is being processed...`);
}
return txReturn;
}
async function decodeTokenURI(result) {
const content = result.substring(130);
let contentClean = "";
for (let i = 0; i < content.length; i += 2) {
let hex = content.substr(i, 2);
let char = String.fromCharCode(parseInt(hex, 16));
contentClean += char;
}
if (contentClean.slice(0, 29) == 'data:application/json;base64,') {
contentClean = reformatBase64(contentClean.slice(29));
contentClean = atob(contentClean);
contentClean = JSON.parse(contentClean);
} else if (contentClean.slice(0, 3) == 'www' || contentClean.slice(0, 3) == 'htt') {
const response = await fetch(contentClean);
contentClean = await response.json();
} else if (contentClean.slice(0, 3) == 'ipf') {
const response = await fetch('https://ipfs.io/ipfs/' + contentClean);
contentClean = await response.json();
}
const name = contentClean.name;
const description = contentClean.description;
const image = contentClean.image;
const animation_url = contentClean.animation_url;
const attributes = contentClean.attributes;
return { name, description, image, animation_url, attributes };
}
async function detailPopUp(id, token, mode) {
const dataURI = '0xc87b56dd' + id;
const result = await request('eth_call', [{ to: '0x' + token, data: dataURI }, 'latest']);
const decodedResult = await decodeTokenURI(result);
const popup = createHtml('div', { id: 'detailPopUp', style: 'position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; background: rgba(0,0,0,0.95); z-index: 1000; display: flex; flex-direction: column; justify-content: center; align-items: flex-start;' });
const body = document.getElementsByTagName('body')[0];
body.appendChild(popup);
const close = createHtml('button', { onclick: () => popup.remove(), style: 'position: absolute; top: 0; right: 0; background: none; border: none; color: aliceblue; font-size: 2em;' });
close.innerHTML = '×';
popup.appendChild(close);
if (mode == 'media') {
let animation_url = decodedResult.animation_url;
let type = 'iframe';
if (animation_url == undefined) {
animation_url = decodedResult.image;
type = 'img';
}
const animation = createHtml(type, { src: animation_url, style: 'max-width: 90vw; min-height: 80vh; max-height: 95vh; object-fit: contain; object-position: center; border: 0; display: flex; flex-direction: column; padding-left: 10%;', scrolling: 'no' });
popup.appendChild(animation);
} else if (mode == 'attributes') {
let attributes = decodedResult.attributes;
if (attributes == undefined) {
attributes = [];
popup.appendChild(createHtml('span', { style: 'padding-left: 30%;'})).innerHTML = 'No attributes available';
} else {
for (let i = 0; i < attributes.length; i++) {
const attribute = createHtml('div', { style: 'margin: 1vh; padding-left: 10%;' });
const name = createHtml('span', { style: 'font-weight: lighter;' });
name.innerHTML = attributes[i].trait_type + ': ';
const value = createHtml('span', { style: 'font-weight: bold;' });
value.innerHTML = attributes[i].value;
attribute.appendChild(name);
attribute.appendChild(value);
popup.appendChild(attribute);
}
}
}
}
function reformatBase64(input) {
const cleaned = input.replace(/[^A-Za-z0-9+/]/g, '');
const padding = cleaned.length % 4 === 0 ? 0 : 4 - (cleaned.length % 4);
return cleaned + '='.repeat(padding);
}
async function checkRoyalties(token) {
const calldata = '0x2a55205a'+'0'.repeat(123)+'186a0'
try {
const result = await request('eth_call', [{ to: '0x'+token, data: calldata }, 'latest']);
royalties = Number(parseInt(result.slice(66),16))/1000;
royaltyAddress = '0x'+result.slice(26, 66);
setHtml('royalties', royalties+'%');
} catch (e) {
royalties = 0;
setHtml('royalties', royalties+'%');
}
}
function updateTotal() {
const price = getHtml('price').value;
const opensea = getHtml('listOS').checked;
incRoyalties = (price*(1+(royalties/100)))
incOpensea = (incRoyalties*(1+openseaFee))
if (opensea) {
setHtml('totalPrice','Ξ'+incRoyalties.toFixed(5)+' here & Ξ'+incOpensea.toFixed(5)+' on OS')
} else {
setHtml('totalPrice','Ξ'+incRoyalties.toFixed(5))
}
}
function moveDecimalLeft15(number) {
const strNum = number.toString();
const decimalIndex = strNum.indexOf('.');
const padSize = decimalIndex < 0 ? 15 : 15 - decimalIndex;
const paddedStr = strNum.replace('.', '').padStart(padSize + 1, '0');
return parseFloat(paddedStr.slice(0, -15) + '.' + paddedStr.slice(-15));
}
function createMsgParams(priceWei,walletAddress,tokenAddress,tokenId,startTime,endTime,salt,counter,considerations,os) {
let zone, conduitKey;
if (os) {
zone = '0x'+'0'.repeat(40);
conduitKey = openseaConduitKey;
} else {
zone = contractAddress;
conduitKey = '0x'+'0'.repeat(64);
}
return JSON.stringify({
'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' }
]
},
'primaryType': 'OrderComponents',
'domain': {
'name': 'Seaport',
'version': '1.4',
'chainId': '5',
'verifyingContract': '0x00000000000001ad428e4906aE43D8F9852d0dD6'
},
'message': {
'offerer': walletAddress,
'offer': [
{
'itemType': '2',
'token': tokenAddress,
'identifierOrCriteria': String(tokenId),
'startAmount': '1',
'endAmount': '1'
}
],
'consideration': [
{
'itemType': '0',
'token': '0x0000000000000000000000000000000000000000',
'identifierOrCriteria': '0',
'startAmount': String(priceWei),
'endAmount': String(priceWei),
'recipient': walletAddress
},
...considerations
],
'orderType': '0',
'startTime': String(startTime),
'endTime': String(endTime),
'zone': zone,
'zoneHash': '0x0000000000000000000000000000000000000000000000000000000000000000',
'salt': String(salt),
'conduitKey': conduitKey,
'counter': String(counter) // to be queried from the seaport contract in subsequent versions, means identical cancelled orders cannot be resubmitted currently
}
});
}
</script>
<style>
body{
margin: 0;
font-family: Bahnschrift, 'DIN Alternate', 'Franklin Gothic Medium', 'Nimbus Sans Narrow', sans-serif-condensed, sans-serif;
word-wrap: break-word;
}
section {
padding: 2vh 5vw 0;
max-width: 100ch;
}
h3 {
margin-top: 5vh;
margin-bottom: 0.5vh;
}
@media (prefers-color-scheme: dark) {
body {
background: #111;
color: aliceblue;
}
}
.fields {
width: 100%;
display:flex;
flex-direction: row;
flex-wrap: wrap; /* Maybe just on sell item? */
gap: 1vw;
justify-items: center;
align-items: center;
}
input {
color: inherit;
flex-grow: 1;
background: #77777750;
}
input,
button {
box-sizing: border-box;
border: none;
border-radius: 8px;
padding: 1.2em 2em;
}
button:hover, .click:hover {
cursor: pointer;
}
.tiles {
border: 1px solid #77777750;
border-radius: 8px;
padding: 1vh;
margin-right: 1vh;
margin-top:1vh;
display:flex;
flex-direction: column;
flex-wrap: wrap;
gap: 1vw;
justify-items: center;
}
</style>
</head>
<body>
<section>
<h1>Onchain Marketplace v0.0.4</h1>
<p style='font-weight: bold;'>An onchain frontend and database for ERC721 trading on top of Seaport Protocol.</p>
<p>⚠️Onchain Marketplace is in alpha, do not interact with the contract with any valuable wallets or NFTs and only use on Goerli testnet⚠️</p>
<span id='welcome'>Welcome!</span><span id='walletAddress'></span>
<p>Start by typing the address of the collection you would like to buy or sell from in the box below (defaults to the Terraform Automata Goerli collection) and connect your wallet with the 'Load Collection' button (make sure to be on the Goerli network). All content is loaded via RPC requests sent to your wallet provider.</p>
<div class="fields">
<input type='text' id='tokenAddress' name='tokenAddress' value='0xa29926934846fbf1000b5bce7a309a89dfb6f05a' />
<button onclick='connect()'>Load Collection</button>
</div>
<p id='txStatus'></p>
</section>
<section style='display: none;' id='sell'>
<div id='forSale' style='display: flex; flex-wrap: wrap;'></div>
<h3>Sell an item from this collection</h3>
<div style="margin-bottom: 2vh; margin-top: 3vh;">
<input type='checkbox' id='listOS' onclick='updateTotal()'/>
<label for="listOS">Also list on OpenSea</label>
</div>
<div class="fields">
<input type='number' id='tokenId' placeholder='token id'/>
<input type='number' id='price' placeholder='price (eth)' oninput='updateTotal()'/>
<input type='number' id='duration' placeholder='duration (days)'/>
<button onclick='sell()' class='sell'>Sell</button>
</div>
<p>Royalties: <span id='royalties'></span> | Total Price: <span id='totalPrice'></span></p>
<h3>Cancel a sale from this collection</h3>
<div class="fields">
<input type='number' id='tokenIdCancel' placeholder='token id'/>
<button onclick='cancel()' class='sell'>Cancel</button>
</div>
<h3>Further information</h3>
<p style='font-weight: bold;'>Buy and cancel orders can be approved directly with one simple wallet transaction. Sell orders however require a few more steps:</p>
<ul>
<li><span style='font-weight: bold;'>Give Seaport access to your NFT: </span> If you haven't approved this NFT for sale previously, you will be asked to give the Seaport contract access to it (0x00000000000001ad428e4906aE43D8F9852d0dD6). This is the same procedure as approving a collection for the first time on Opensea, with the added safety of only approving one specific NFT from the collection.</li>
<li><span style='font-weight: bold;'>Sign your sell order: </span> Next, you will be asked to sign your sell order. Your wallet will show you the parameters of the order before signing. This is required for each sale, and functions the same on Opensea.</li>
<li><span style='font-weight: bold;'>Save the order in the Onchain Marketplace database: </span> One final step is required to store your sell order in the Onchain Marketplace storage, this is the last transaction that will appear on your screen. Marketplaces such as Opensea don't require this step as they store your order off-chain.</li>
</ul>
</section>
</body>
</html>