When I am running the midight APIs locally it’s working fine but when I am running it in docker compose up –build or npm run build && npm run start I am having these problems
Starting NFT lock process…
Seller: Abhinav
**NFT ID: abc123.mynft Contract Address: 02008a841b51c47a26346754a0dc907c50c0c1a0d51791cb38c16f017cd7ydd50 Building wallet… Waiting for wallet to sync… scala.scalajs.js.JavaScriptException: TypeError: Cannot read properties of undefined (reading ‘c5’) at Kq(/home/abhinav/Correcting-Luxechain-Build problem/luxechain-main-nextjs/.next/server/chunks/6181.js:113:1028064) at {anonymous}()(/home/abhinav/Correcting-Luxechain-Build problem/luxechain-main-nextjs/.next/server/chunks/6181.js:113:1052814) at o.eZ(/home/abhinav/Correcting-Luxechain-Build problem/luxechain-main-nextjs/.next/server/chunks/6181.js:113:1052839) at o.eZ(/home/abhinav/Correcting-Luxechain-Build problem/luxechain-main-nextjs/.next/server/chunks/6181.js:113:416129) at FK.a09(/home/abhinav/Correcting-Luxechain-Build problem/luxechain-main-nextjs/.next/server/chunks/6181.js:113:681725) at {anonymous}()(node:internal/process/task_queues:140:7) at AsyncResource.runInAsyncScope(node:async_hooks:203:9) at AsyncResource.runMicrotask(node:internal/process/task_queues:137:8) at runNextTicks(node:internal/process/task_queues:60:5) at process.processImmediate(node:internal/timers:447:9) scala.scalajs.js.JavaScriptException: TypeError: Cannot read properties of undefined (reading ‘c5’) at Kq(/home/abhinav/Correcting-Luxechain-Build problem/luxechain-main-nextjs/.next/server/chunks/6181.js:113:1028064) at {anonymous}()(/home/abhinav/Correcting-Luxechain-Build problem/luxechain-main-nextjs/.next/server/chunks/6181.js:113:1052814) at o.eZ(/home/abhinav/Correcting-Luxechain-Build problem/luxechain-main-nextjs/.next/server/chunks/6181.js:113:1052839) at o.eZ(/home/abhinav/Correcting-Luxechain-Build problem/luxechain-main-nextjs/.next/server/chunks/6181.js:113:416129) at FK.a09(/home/abhinav/Correcting-Luxechain-Build problem/luxechain-main-nextjs/.next/server/chunks/6181.js:113:681725) at {anonymous}()(node:internal/process/task_queues:140:7) at AsyncResource.runInAsyncScope(node:async_hooks:203:9) at AsyncResource.runMicrotask(node:internal/process/task_queues:137:8) at runNextTicks(node:internal/process/task_queues:60:5) at process.processImmediate(node:internal/timers:447:9) scala.scalajs.js.JavaScriptException: TypeError: Cannot read properties of undefined (reading ‘c5’) at Kq(/home/abhinav/Correcting-Luxechain-Build problem/luxechain-main-nextjs/.next/server/chunks/6181.js:113:1028064) at {anonymous}()(/home/abhinav/Correcting-Luxechain-Build problem/luxechain-main-nextjs/.next/server/chunks/6181.js:113:1052814) at o.eZ(/home/abhinav/Correcting-Luxechain-Build problem/luxechain-main-nextjs/.next/server/chunks/6181.js:113:1052839) at o.eZ(/home/abhinav/Correcting-Luxechain-Build problem/luxechain-main-nextjs/.next/server/chunks/6181.js:113:416129) at FK.a09(/home/abhinav/Correcting-Luxechain-Build problem/luxechain-main-nextjs/.next/server/chunks/6181.js:113:681725) at {anonymous}()(node:internal/process/task_queues:140:7) at AsyncResource.runInAsyncScope(node:async_hooks:203:9) at AsyncResource.runMicrotask(node:internal/process/task_queues:137:8) scala.scalajs.js.JavaScriptException: TypeError: Cannot read properties of undefined (reading ‘c5’) at Kq(/home/abhinav/Correcting-Luxechain-Build problem/luxechain-main-nextjs/.next/server/chunks/6181.js:113:1028064) at {anonymous}()(/home/abhinav/Correcting-Luxechain-Build problem/luxechain-main-nextjs/.next/server/chunks/6181.js:113:1052814) at o.eZ(/home/abhinav/Correcting-Luxechain-Build problem/luxechain-main-nextjs/.next/server/chunks/6181.js:113:1052839) at o.eZ(/home/abhinav/Correcting-Luxechain-Build problem/luxechain-main-nextjs/.next/server/chunks/6181.js:113:416129) at FK.a09(/home/abhinav/Correcting-Luxechain-Build problem/luxechain-main-nextjs/.next/server/chunks/6181.js:113:681725) at {anonymous}()(node:internal/process/task_queues:140:7) at AsyncResource.runInAsyncScope(node:async_hooks:203:9) at AsyncResource.runMicrotask(node:internal/process/task_queues:137:8) scala.scalajs.js.JavaScriptException: TypeError: Cannot read properties of undefined (reading ‘c5’) at Kq(/home/abhinav/Correcting-Luxechain-Build problem/luxechain-main-nextjs/.next/server/chunks/6181.js:113:1028064) at {anonymous}()(/home/abhinav/Correcting-Luxechain-Build problem/luxechain-main-nextjs/.next/server/chunks/6181.js:113:1052814) at o.eZ(/home/abhinav/Correcting-Luxechain-Build problem/luxechain-main-nextjs/.next/server/chunks/6181.js:113:1052839) at o.eZ(/home/abhinav/Correcting-Luxechain-Build problem/luxechain-main-nextjs/.next/server/chunks/6181.js:113:416129) at FK.a09(/home/abhinav/Correcting-Luxechain-Build problem/luxechain-main-nextjs/.next/server/chunks/6181.js:113:681725) at {anonymous}()(node:internal/process/task_queues:140:7) at AsyncResource.runInAsyncScope(node:async_hooks:203:9) at AsyncResource.runMicrotask(node:internal/process/task_queues:137:8) scala.scalajs.js.JavaScriptException: TypeError: Cannot read properties of undefined (reading ‘c5’) at Kq(/home/abhinav/Correcting-Luxechain-Build problem/luxechain-main-nextjs/.next/server/chunks/6181.js:113:1028064) at {anonymous}()(/home/abhinav/Correcting-Luxechain-Build problem/luxechain-main-nextjs/.next/server/chunks/6181.js:113:1052814) at o.eZ(/home/abhinav/Correcting-Luxechain-Build problem/luxechain-main-nextjs/.next/server/chunks/6181.js:113:1052839) at o.eZ(/home/abhinav/Correcting-Luxechain-Build problem/luxechain-main-nextjs/.next/server/chunks/6181.js:113:416129) at FK.a09(/home/abhinav/Correcting-Luxechain-Build problem/luxechain-main-nextjs/.next/server/chunks/6181.js:113:681725) at {anonymous}()(node:internal/process/task_queues:140:7) at AsyncResource.runInAsyncScope(node:async_hooks:203:9) at AsyncResource.runMicrotask(node:internal/process/task_queues:137:8)
This is my code
**
// Next.js API route for NFT locking functionality (App Router)
// This extracts the core logic from the CLI app into a REST API
import { WalletBuilder } from ‘@midnight-ntwrk/wallet’;
import {
createNFTVerificationPrivateState,
witnesses,
} from “../../../contract-nft-verification/dist/witnesses”;
import { NFTVerification} from “../../../contract-nft-verification/dist”;
import { findDeployedContract } from ‘@midnight-ntwrk/midnight-js-contracts’;
import { httpClientProofProvider } from ‘@midnight-ntwrk/midnight-js-http-client-proof-provider’;
import { indexerPublicDataProvider } from ‘@midnight-ntwrk/midnight-js-indexer-public-data-provider’;
// import { levelPrivateStateProvider } from ‘@midnight-ntwrk/midnight-js-level-private-state-provider’;
import { NodeZkConfigProvider } from ‘@midnight-ntwrk/midnight-js-node-zk-config-provider’;
import { createBalancedTx } from ‘@midnight-ntwrk/midnight-js-types’;
import { Transaction as ZswapTransaction } from ‘@midnight-ntwrk/zswap’;
import { Transaction } from ‘@midnight-ntwrk/ledger’;
import { fromHex, toHex } from ‘@midnight-ntwrk/midnight-js-utils’;
import { getLedgerNetworkId, getZswapNetworkId } from ‘@midnight-ntwrk/midnight-js-network-id’;
import { NetworkId, setNetworkId } from ‘@midnight-ntwrk/midnight-js-network-id’;
import * as Rx from ‘rxjs’;
import { createHash } from ‘node:crypto’;
import path from ‘node:path’;
// Custom private state provider that implements the required interface
class CustomPrivateStateProvider {
constructor(signingKey) {
this.state = new Map();
this._signingKey = signingKey;
}
async get(key) {
return this.state.get(key);
}
async set(key, value) {
this.state.set(key, value);
}
async delete(key) {
this.state.delete(key);
}
async clear() {
this.state.clear();
}
async getSigningKey() {
return this._signingKey;
}
}
// Set network to testnet
setNetworkId(NetworkId.TestNet);
// Configuration (you might want to move this to environment variables)
const CONFIG = {
indexer**:** ‘https://indexer.testnet-02.midnight.network/api/v1/graphql’,
indexerWS**:** ‘wss://indexer.testnet-02.midnight.network/api/v1/graphql/ws’,
node**:** ‘https://rpc.testnet-02.midnight.network’,
proofServer**:** ‘http://127.0.0.1:6300’, // Make sure this is running locally
// proofServer: ‘http://proof-server:6300’,
privateStateStoreName**:** ‘nft-verification-private-state’,
zkConfigPath**:** path.resolve(process.cwd(), ‘contract-nft-verification’, ‘dist’, ‘managed’, ‘NFTVerification’)
};
// Helper function to convert asset ID to 64-character hex (from the original code)
function get64HexFromAssetId(assetId) {
let fullHex;
if (assetId.includes(‘.’)) {
const [policyId, assetName] = assetId.split(‘.’);
const assetNameHex = Buffer.from(assetName, ‘utf8’).toString(‘hex’);
fullHex = policyId + assetNameHex;
} else {
fullHex = assetId;
}
const hash = createHash(‘sha256’).update(Buffer.from(fullHex, ‘hex’)).digest(‘hex’);
return hash;
}
// Helper function to wait for wallet sync
const waitForSync = (wallet) =>
Rx.firstValueFrom(
wallet.state().pipe(
Rx.throttleTime(5_000),
Rx.filter((state) => {
return state.syncProgress !== undefined && state.syncProgress.synced;
}),
),
);
// Helper function to create wallet and midnight provider
const createWalletAndMidnightProvider = async (wallet) => {
const state = await Rx.firstValueFrom(wallet.state());
return {
coinPublicKey**:** state.coinPublicKey,
encryptionPublicKey**:** state.encryptionPublicKey,
balanceTx(tx, newCoins) {
return wallet
.balanceTransaction(
ZswapTransaction.deserialize(tx.serialize(getLedgerNetworkId()), getZswapNetworkId()),
newCoins,
)
.then((tx) => wallet.proveTransaction(tx))
.then((zswapTx) => Transaction.deserialize(zswapTx.serialize(getZswapNetworkId()), getLedgerNetworkId()))
.then(createBalancedTx);
},
submitTx(tx) {
return wallet.submitTransaction(tx);
},
};
};
export async function POST(request) {
try {
const { sellerName, nftId, walletSeed, contractAddress } = await request.json();
// Validate required fields
if (!sellerName || !nftId || !walletSeed || !contractAddress) {
return Response.json({
error**:** ‘Missing required fields. Please provide: sellerName, nftId, walletSeed, contractAddress’
}, { status**:** 400 });
}
console.log(‘Starting NFT lock process…’);
console.log(‘Seller:’, sellerName);
console.log(‘NFT ID:’, nftId);
console.log(‘Contract Address:’, contractAddress);
// Step 1: Build wallet from seed
console.log(‘Building wallet…’);
const wallet = await WalletBuilder.buildFromSeed(
CONFIG.indexer,
CONFIG.indexerWS,
CONFIG.proofServer,
CONFIG.node,
walletSeed,
getZswapNetworkId(),
‘info’
);
wallet.start();
// Wait for wallet to sync
console.log(‘Waiting for wallet to sync…’);
await waitForSync(wallet);
const state = await Rx.firstValueFrom(wallet.state());
console.log(‘Wallet address:’, state.address);
console.log(‘Wallet state keys:’, Object.keys(state));
// Step 2: Setup providers
console.log(‘Setting up providers…’);
const walletAndMidnightProvider = await createWalletAndMidnightProvider(wallet);
// Create private state provider with wallet’s signing key
// For now, we’ll derive a signing key from the wallet seed since the exact property might vary
let signingKey;
if (state.coinPrivateKey) {
signingKey = state.coinPrivateKey;
} else if (state.privateKey) {
signingKey = state.privateKey;
} else {
// Derive a signing key from the wallet seed as fallback
const seedBytes = fromHex(walletSeed);
signingKey = seedBytes.slice(0, 32); // Use first 32 bytes as signing key
}
const privateStateProvider = new CustomPrivateStateProvider(signingKey);
const providers = {
privateStateProvider,
publicDataProvider**:** indexerPublicDataProvider(CONFIG.indexer, CONFIG.indexerWS),
zkConfigProvider**:** new NodeZkConfigProvider(CONFIG.zkConfigPath),
proofProvider**:** httpClientProofProvider(CONFIG.proofServer),
walletProvider**:** walletAndMidnightProvider,
midnightProvider**:** walletAndMidnightProvider,
};
// Step 3: Connect to existing contract
console.log(‘Connecting to contract…’);
const nftContractInstance = new NFTVerification.Contract(witnesses);
const contract = await findDeployedContract(providers, {
contractAddress,
contract**:** nftContractInstance,
privateStateId**:** ‘nftVerificationPrivateState’,
initialPrivateState**:** createNFTVerificationPrivateState(‘’, new Uint8Array()),
});
console.log(‘Connected to contract at:’, contract.deployTxData.public.contractAddress);
// Step 4: Prepare NFT data
const nftIDHex = get64HexFromAssetId(nftId);
const nftIdBytes = fromHex(nftIDHex);
// Step 5: Set private state
console.log(‘Setting private state…’);
const privateState = createNFTVerificationPrivateState(sellerName, nftIdBytes);
await providers.privateStateProvider.set(‘nftVerificationPrivateState’, privateState);
// Step 6: Lock the NFT
console.log(‘Locking NFT…’);
const tx = await contract.callTx.lockNFT();
const { txHash, blockHeight } = tx.public;
const hashedUsername = tx.private.result;
// Convert the result to hex
const hexedUsername = toHex(new Uint8Array(hashedUsername));
console.log(‘NFT locked successfully!’);
console.log(‘Transaction hash:’, txHash);
console.log(‘Block height:’, blockHeight);
console.log(‘Hashed username:’, hexedUsername);
// Step 7: Close wallet
await wallet.close();
// Return success response
return Response.json({
success**:** true,
message**:** ‘NFT locked successfully’,
data**:** {
transactionHash**:** txHash,
blockHeight**:** blockHeight,
hashedUsername**:** hexedUsername,
sellerName**:** sellerName,
nftId**:** nftId,
contractAddress**:** contractAddress
}
});
} catch (error) {
console.error(‘Error locking NFT:’, error);
return Response.json({
success**:** false,
error**:** ‘Failed to lock NFT’,
message**:** error.message,
details**:** error.stack
}, { status**:** 500 });
}
}