Palindrome Crypto Pay - Blockchain Escrow Payment Solution

Escrow Queries

getNextEscrowId

async getNextEscrowId(): Promise<bigint>

Reads the nextEscrowId counter from the contract. This is the ID that will be assigned to the next escrow created.

Parameters

None

Returns

Promise<bigint> – The next escrow ID

import { createPalindromeSDK } from '@/lib/createSDK';

const { sdk } = await connectAndInitSDK();

const nextId = await sdk.getNextEscrowId();
console.log("Next escrow will be ID:", nextId);

// If nextId is 42n, the next escrow created will have ID 42
// After creation, nextEscrowId becomes 43

Common Use Cases

1. Predict wallet address before creation:

const nextId = await sdk.getNextEscrowId();
const walletAddress = await sdk.predictWalletAddress(nextId);
console.log("Future escrow wallet:", walletAddress);

2. Pre-sign authorizations:

const nextId = await sdk.getNextEscrowId();
const predictedWallet = await sdk.predictWalletAddress(nextId);
const sig = await sdk.signWalletAuthorization(walletClient, predictedWallet, nextId);

3. Track total escrows created:

const nextId = await sdk.getNextEscrowId();
const totalEscrows = Number(nextId); // IDs start at 0, so nextId = total count
console.log("Total escrows created:", totalEscrows);

4. Display in UI:

function EscrowStats() {
  const [totalEscrows, setTotalEscrows] = useState(0);

  useEffect(() => {
    sdk.getNextEscrowId().then(id => setTotalEscrows(Number(id)));
  }, []);

  return <div>Total Escrows: {totalEscrows}</div>;
}

Race Condition Warning

If multiple users create escrows simultaneously, the predicted ID might change:

// User A gets nextId = 42
const nextIdA = await sdk.getNextEscrowId();

// User B creates escrow → nextId becomes 43
await sdkB.createEscrow(...);

// User A's prediction is now wrong!
// The escrow they create will be ID 43, not 42

The SDK handles this internally by checking the event logs after creation, but be aware of this when building custom flows.

See alsopredictWalletAddress() · createEscrow()

Previous
getEscrowDetail