Monorepo for Aesthetic.Computer
aesthetic.computer
1#!/usr/bin/env node
2
3/**
4 * Update v4 contract metadata
5 */
6
7import { TezosToolkit } from '@taquito/taquito';
8import { InMemorySigner } from '@taquito/signer';
9import fs from 'fs';
10import path from 'path';
11import { fileURLToPath } from 'url';
12
13const __filename = fileURLToPath(import.meta.url);
14const __dirname = path.dirname(__filename);
15
16// V4 staging contract
17const V4_CONTRACT = 'KT1ER1GyoeRNhkv6E57yKbBbEKi5ynKbaH3W';
18
19// Load staging wallet credentials
20const stagingEnvPath = path.join(__dirname, 'staging/.env');
21const envContent = fs.readFileSync(stagingEnvPath, 'utf8');
22let stagingAddress, stagingKey;
23for (const line of envContent.split('\n')) {
24 if (line.startsWith('STAGING_ADDRESS=') || line.startsWith('ADDRESS=')) {
25 stagingAddress = line.split('=')[1].trim().replace(/"/g, '');
26 } else if (line.startsWith('STAGING_KEY=') || line.startsWith('KEY=') || line.startsWith('SECRET_KEY=')) {
27 stagingKey = line.split('=')[1].trim().replace(/"/g, '');
28 }
29}
30
31if (!stagingAddress || !stagingKey) {
32 console.error('❌ Could not load staging wallet credentials');
33 process.exit(1);
34}
35
36const tezos = new TezosToolkit('https://mainnet.api.tez.ie');
37tezos.setProvider({ signer: new InMemorySigner(stagingKey) });
38
39console.log('\n╔══════════════════════════════════════════════════════════════╗');
40console.log('║ 📝 Update v4 Contract Metadata ║');
41console.log('╚══════════════════════════════════════════════════════════════╝\n');
42
43console.log(`📍 Contract: ${V4_CONTRACT}`);
44console.log(`👤 Admin: ${stagingAddress}\n`);
45
46// Read new metadata
47const metadataJson = JSON.parse(fs.readFileSync('/tmp/v4-metadata.json', 'utf8'));
48const metadataString = JSON.stringify(metadataJson);
49const metadataBytes = Buffer.from(metadataString, 'utf8').toString('hex');
50
51console.log('📄 New metadata:');
52console.log(JSON.stringify(metadataJson, null, 2));
53console.log();
54
55// Prepare contract call
56console.log('📤 Calling set_contract_metadata...');
57
58try {
59 const contract = await tezos.contract.at(V4_CONTRACT);
60
61 // Call set_contract_metadata with [{ key: "content", value: bytes }]
62 const op = await contract.methods.set_contract_metadata([{
63 key: 'content',
64 value: metadataBytes
65 }]).send();
66
67 console.log(` ⏳ Operation hash: ${op.hash}`);
68 console.log(' ⏳ Waiting for confirmation...');
69
70 await op.confirmation(1);
71
72 console.log('\n✅ Contract metadata updated!');
73 console.log(` 🔗 Explorer: https://tzkt.io/${op.hash}\n`);
74
75} catch (error) {
76 console.error('\n❌ Update failed!');
77 console.error(` Error: ${error.message}\n`);
78 process.exit(1);
79}