-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
303 lines (272 loc) · 10 KB
/
Copy pathindex.html
File metadata and controls
303 lines (272 loc) · 10 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>IP Asset Minter</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 800px;
margin: 0 auto;
padding: 2rem;
background: #f9f9f9;
}
.container {
background: white;
padding: 2rem;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
h1 {
color: #333;
margin-bottom: 2rem;
}
.form-group {
margin-bottom: 1.5rem;
}
label {
display: block;
margin-bottom: 0.5rem;
color: #555;
}
input {
width: 100%;
padding: 0.75rem;
border: 1px solid #ddd;
border-radius: 4px;
font-size: 1rem;
box-sizing: border-box;
}
input[type="number"] {
width: 100%;
padding: 0.75rem;
border: 1px solid #ddd;
border-radius: 4px;
font-size: 1rem;
}
button {
background-color: #4CAF50;
color: white;
padding: 0.75rem 1.5rem;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 1rem;
width: 100%;
}
button:disabled {
background-color: #ccc;
}
.message {
margin-top: 1rem;
padding: 1rem;
border-radius: 4px;
}
.success {
background-color: #d4edda;
border: 1px solid #c3e6cb;
color: #155724;
}
.error {
background-color: #f8d7da;
border: 1px solid #f5c6cb;
color: #721c24;
}
details {
margin-top: 1rem;
}
summary {
cursor: pointer;
color: #4a4a4a;
padding: 0.5rem 0;
}
pre {
background: #f5f5f5;
padding: 1rem;
border-radius: 4px;
overflow-x: auto;
}
</style>
</head>
<body>
<div class="container">
<h1>IP Asset Minter</h1>
<form id="mintForm">
<div class="form-group">
<label for="name">Voice Character Name</label>
<input
id="name"
type="text"
required
placeholder="e.g., Morgan Freeman"
>
</div>
<div class="form-group">
<label for="imageUrl">Character Image URL</label>
<input
id="imageUrl"
type="url"
required
placeholder="Enter the URL of the character's image"
>
</div>
<div class="form-group">
<label for="voiceUrl">Voice Sample URL</label>
<input
id="voiceUrl"
type="url"
required
placeholder="Enter the URL of the voice sample (MP3)"
>
</div>
<div class="form-group">
<label for="mintingFee">Minting Fee (WIP Tokens)</label>
<input
id="mintingFee"
type="number"
required
min="1"
value="100"
placeholder="Enter minting fee in WIP tokens"
>
</div>
<button type="submit" id="submitButton">Mint IP Asset</button>
</form>
<div id="message" style="display: none;" class="message"></div>
<div id="details" style="display: none;">
<details>
<summary>View Details</summary>
<pre id="resultJson"></pre>
</details>
</div>
</div>
<script>
let apiKey = '';
// Fetch API key from server
async function fetchConfig() {
try {
const response = await fetch('/config');
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const config = await response.json();
apiKey = config.apiKey;
} catch (error) {
console.error('Failed to fetch API key:', error);
showError('Failed to initialize. Please check your connection and refresh the page.');
}
}
function showError(message) {
const messageDiv = document.getElementById('message');
messageDiv.className = 'message error';
messageDiv.textContent = `❌ ${message}`;
messageDiv.style.display = 'block';
}
const form = document.getElementById('mintForm');
const submitButton = document.getElementById('submitButton');
const messageDiv = document.getElementById('message');
const detailsDiv = document.getElementById('details');
const resultJson = document.getElementById('resultJson');
form.addEventListener('submit', async (e) => {
e.preventDefault();
if (!apiKey) {
showError('API key not available. Please refresh the page.');
return;
}
const name = document.getElementById('name').value;
const imageUrl = document.getElementById('imageUrl').value;
const voiceUrl = document.getElementById('voiceUrl').value;
const mintingFee = parseInt(document.getElementById('mintingFee').value, 10);
submitButton.disabled = true;
submitButton.textContent = 'Minting...';
messageDiv.style.display = 'none';
detailsDiv.style.display = 'none';
try {
const response = await fetch('https://staging.crossmint.com/api/v1/ip/collections/f44f5c02-6fb4-4841-9423-e1e192a1c539/ipassets', {
method: 'POST',
headers: {
'X-API-KEY': apiKey,
'Content-Type': 'application/json',
'Accept': 'application/json'
},
body: JSON.stringify({
owner: 'email:creator@example.com:story-testnet',
nftMetadata: {
name: `${name} Voice License`,
description: `A voice sample of the iconic narration style of ${name}`,
image: imageUrl
},
ipAssetMetadata: {
title: `${name} Voice Model`,
createdAt: new Date().toISOString(),
ipType: 'voice',
creators: [
{
name: 'AI Voice Labs',
email: 'creator@example.com',
crossmintUserLocator: 'email:creator@example.com:story-testnet',
contributionPercent: 100
}
],
media: [
{
name: `${name} Voice Sample`,
url: voiceUrl,
mimeType: 'audio/mpeg'
}
],
attributes: [
{
key: 'Voice Type',
value: 'Narration'
},
{
key: 'Voice Character',
value: name
},
{
key: 'License Type',
value: 'Commercial Use'
}
]
},
licenseTerms: [{
type: 'commercial-use',
terms: {
defaultMintingFee: mintingFee,
currency: '0x1514000000000000000000000000000000000000'
}
}]
})
});
if (!response.ok) {
const errorText = await response.text();
throw new Error(`HTTP error! status: ${response.status}\n${errorText}`);
}
const data = await response.json();
messageDiv.style.display = 'block';
if (response.status === 502) {
messageDiv.className = 'message error';
messageDiv.textContent = '❌ API temporarily unavailable. Please try again in a few minutes.';
} else {
messageDiv.className = 'message success';
messageDiv.textContent = '✅ IP Asset minted successfully!';
detailsDiv.style.display = 'block';
resultJson.textContent = JSON.stringify(data, null, 2);
}
} catch (error) {
messageDiv.style.display = 'block';
messageDiv.className = 'message error';
messageDiv.textContent = `❌ Error: ${error.message}`;
console.error('Minting error:', error);
} finally {
submitButton.disabled = false;
submitButton.textContent = 'Mint IP Asset';
}
});
// Initialize by fetching the API key
fetchConfig();
</script>
</body>
</html>