@@ -10,26 +10,20 @@ async function main() {
1010 dotenv . config ( )
1111
1212 // Load contract addresses from deployment files
13- const deploymentsGov = require ( "../deployments/sepolia/CrosschainGov.json" )
14- const GOV_ADDRESS = deploymentsGov . address
1513 const deploymentsNFT = require ( "../deployments/sepolia/CrosschainNFT.json" )
1614 const NFT_ADDRESS = deploymentsNFT . address
17- const PROOF_HANDLER_ADDRESS = deploymentsGov . libraries . ProofHandler
15+ const PROOF_HANDLER_ADDRESS = deploymentsNFT . libraries . ProofHandler
1816
1917 // Get token info
2018 if ( ! process . env . TOKENID && process . env . TOKENID !== "0" ) {
2119 throw new Error ( "No token ID specified in .env" )
2220 }
2321 const TOKEN_ID = parseInt ( process . env . TOKENID )
2422
25- // Log the environment variable for debugging
26- console . log ( "TOKENID environment variable:" , process . env . TOKENID )
27-
2823 const NEW_URI =
2924 "https://bafkreifnnreoxxgkhty7v2w3qwiie6cfxpv3vcco2xldekfvbiem3nm6dm.ipfs.w3s.link/"
3025
31- console . log ( "Generating metadata update proof..." )
32- console . log ( "Gov Address:" , GOV_ADDRESS )
26+ console . log ( "\nGenerating metadata update proof..." )
3327 console . log ( "NFT Address:" , NFT_ADDRESS )
3428 console . log ( "ProofHandler Address:" , PROOF_HANDLER_ADDRESS )
3529 console . log ( "Token ID:" , TOKEN_ID )
@@ -55,46 +49,39 @@ async function main() {
5549 [ TOKEN_ID , NEW_URI ]
5650 )
5751
58- // Generate the operation proof
59- // Operation type 2 is SET_METADATA
52+ // Generate the operation proof (Operation type 2 is SET_METADATA)
6053 const proof = await nft . generateOperationProof ( 2 , encodedParams )
6154
6255 console . log ( "\nProof generated successfully!" )
6356 console . log ( "\nProof:" , proof )
6457
65- // Create the proof object in the expected format
66- const proofData = {
67- tokenId : TOKEN_ID ,
68- proof : proof ,
69- owner : undefined , // Not needed for metadata update
70- nonce : 1 // Start with nonce 1 for metadata updates
71- }
72-
73- // Add the new token ID to .env file
58+ // Update .env file with the proof
7459 const envPath = path . resolve ( __dirname , "../.env" )
7560 let envContent = ""
61+
7662 try {
7763 // Read existing .env content if file exists
7864 if ( fs . existsSync ( envPath ) ) {
7965 envContent = fs . readFileSync ( envPath , "utf8" )
8066 }
8167
82- // Remove existing TOKENID line if it exists
83- envContent = envContent . replace ( / ^ T O K E N I D = .* $ / m, "" )
68+ // Remove existing PROOF line if it exists
69+ envContent = envContent . replace ( / ^ P R O O F = .* $ / m, "" )
8470
8571 // Add new line if content doesn't end with one
8672 if ( envContent . length > 0 && ! envContent . endsWith ( "\n" ) ) {
8773 envContent += "\n"
8874 }
8975
90- // Add the new TOKENID
91- envContent += `TOKENID =${ TOKEN_ID } \n`
76+ // Add the new PROOF
77+ envContent += `PROOF =${ proof } \n`
9278
9379 // Write back to .env file
9480 fs . writeFileSync ( envPath , envContent )
95- console . log ( "\nToken ID has been written to .env file" )
81+ console . log ( "\nProof has been saved to .env file" )
9682 } catch ( error ) {
9783 console . error ( "Error updating .env file:" , error )
84+ throw error
9885 }
9986 } catch ( error : any ) {
10087 console . error ( "\nError generating proof:" , error )
0 commit comments