Documentation Index
Fetch the complete documentation index at: https://mintlify.com/1inch/cross-chain-sdk/llms.txt
Use this file to discover all available pages before exploring further.
Overview
The submitSecret() method submits a secret preimage to the relayer, allowing resolvers to unlock escrow funds and complete a fill.
Method Signature
async submitSecret(orderHash: string, secret: string): Promise<void>
Parameters
The order hash for which to submit the secret
The 32-byte hex-encoded secret preimage (must start with ‘0x’)This is the original secret used to create the hash lock, not the hash of the secret.
Returns
Promise<void> - Resolves when the secret is successfully submitted
When to Submit Secrets
Secrets should be submitted when:
- Escrows are deployed - Both source and destination escrows must be created
- Ready to accept - Use
getReadyToAcceptSecretFills() to check readiness
- Security validated - Verify escrow addresses and parameters before revealing secrets
Never submit secrets before validating escrow deployments. Malicious resolvers could steal funds if secrets are revealed prematurely.
Examples
Basic Secret Submission
import { SDK } from '@1inch/cross-chain-sdk'
const sdk = new SDK({
url: 'https://api.1inch.com/fusion-plus',
authKey: 'your-auth-key'
})
// After creating and submitting an order
const orderHash = '0x...'
const secret = '0x...' // Original secret from order creation
// Check if ready to accept secret
const { fills } = await sdk.getReadyToAcceptSecretFills(orderHash)
if (fills.length > 0) {
// Submit secret for the ready fill
await sdk.submitSecret(orderHash, secret)
console.log('Secret submitted successfully')
}
Multiple Secrets (Multi-Fill Order)
import { OrderStatus } from '@1inch/cross-chain-sdk'
// Track which secrets have been submitted
const submittedSecrets = new Set<number>()
while (true) {
// Check for ready fills
const { fills } = await sdk.getReadyToAcceptSecretFills(orderHash)
// Submit secrets for new ready fills
for (const { idx } of fills) {
if (!submittedSecrets.has(idx)) {
console.log(`Submitting secret ${idx}...`)
await sdk.submitSecret(orderHash, secrets[idx])
submittedSecrets.add(idx)
console.log(`Secret ${idx} submitted`)
}
}
// Check order status
const { status } = await sdk.getOrderStatus(orderHash)
if (
status === OrderStatus.Executed ||
status === OrderStatus.Expired ||
status === OrderStatus.Refunded
) {
console.log(`Order completed with status: ${status}`)
break
}
// Wait before checking again
await new Promise(resolve => setTimeout(resolve, 2000))
}
With Error Handling
async function submitSecretSafely(
sdk: SDK,
orderHash: string,
secret: string,
maxRetries: number = 3
): Promise<boolean> {
for (let attempt = 1; attempt <= maxRetries; attempt++) {
try {
await sdk.submitSecret(orderHash, secret)
console.log('Secret submitted successfully')
return true
} catch (error) {
console.error(`Attempt ${attempt} failed:`, error)
if (attempt < maxRetries) {
// Exponential backoff
const delay = Math.pow(2, attempt) * 1000
await new Promise(resolve => setTimeout(resolve, delay))
}
}
}
console.error('Failed to submit secret after all retries')
return false
}
// Usage
await submitSecretSafely(sdk, orderHash, secret)
Validating Escrow Before Secret Submission
import { SDK, OrderStatus } from '@1inch/cross-chain-sdk'
// Get order status to validate escrow deployments
const orderStatus = await sdk.getOrderStatus(orderHash)
if (orderStatus.status !== OrderStatus.Created) {
throw new Error(`Order not in created state: ${orderStatus.status}`)
}
// Validate source escrow
const srcEscrow = orderStatus.fills[0]?.srcEscrow
if (!srcEscrow) {
throw new Error('Source escrow not deployed yet')
}
// Validate destination escrow
const dstEscrow = orderStatus.fills[0]?.dstEscrow
if (!dstEscrow) {
throw new Error('Destination escrow not deployed yet')
}
// TODO: Add your validation logic here
// - Verify escrow addresses match expected values
// - Check escrow balances
// - Validate time locks
// - Confirm token addresses and amounts
console.log('Escrows validated, safe to submit secret')
// Now submit the secret
const { fills } = await sdk.getReadyToAcceptSecretFills(orderHash)
if (fills.length > 0) {
await sdk.submitSecret(orderHash, secrets[fills[0].idx])
}
Secret Submission Flow
Monitor order status
Use getOrderStatus() to track order lifecycle and escrow deployments
Check readiness
Call getReadyToAcceptSecretFills() to see which secrets can be submitted
Validate escrows
Critical: Verify escrow addresses, amounts, and parameters before submitting
Submit secret
Call submitSecret() with the order hash and secret preimage
Wait for execution
Resolver uses the secret to unlock escrows and complete the swap
Security Considerations
Always validate escrow deployments before submitting secrets. Check:
- Escrow addresses match expected values
- Token addresses and amounts are correct
- Time locks provide sufficient protection
- No unusual parameters in escrow configuration
Secrets are revealed to resolvers upon submission. This allows them to unlock the destination escrow and receive their fee.
For multi-fill orders, you submit one secret per fill as each becomes ready. The order completes when all fills are executed.
Common Errors
| Error | Cause | Solution |
|---|
| ”Invalid secret format” | Secret not 32-byte hex | Ensure secret is hex-encoded with ‘0x’ prefix |
| ”Secret hash mismatch” | Wrong secret for order | Verify you’re using the correct secret from order creation |
| ”Order not found” | Invalid order hash | Check order hash is correct |
| ”Not ready to accept” | Escrows not deployed | Wait for escrows to be created |
| ”Secret already submitted” | Duplicate submission | Track submitted secrets to avoid duplicates |