{"record":{"id":"1b139aad4847e030","repo":"FuelLabs/fuels-ts","slug":"coins-asset-id-mismatch","errorCode":"COINS_ASSET_ID_MISMATCH","errorMessage":"All coins to consolidate must be from the same asset id.","messagePattern":"All coins to consolidate must be from the same asset id\\.","errorType":"exception","errorClass":"FuelError","httpStatus":null,"severity":"error","filePath":"packages/account/src/account.ts","lineNumber":1279,"sourceCode":"\n  /** @hidden * */\n  private validateTransferAmount(amount: BigNumberish) {\n    if (bn(amount).lte(0)) {\n      throw new FuelError(\n        ErrorCode.INVALID_TRANSFER_AMOUNT,\n        'Transfer amount must be a positive number.'\n      );\n    }\n  }\n\n  /** @hidden * */\n  private validateConsolidationTxsCoins(coins: Coin[], assetId: string) {\n    if (coins.length <= 1) {\n      throw new FuelError(ErrorCode.NO_COINS_TO_CONSOLIDATE, 'No coins to consolidate.');\n    }\n\n    if (!coins.every((c) => c.assetId === assetId)) {\n      throw new FuelError(\n        ErrorCode.COINS_ASSET_ID_MISMATCH,\n        'All coins to consolidate must be from the same asset id.'\n      );\n    }\n  }\n\n  /** @hidden * */\n  private async setTransactionStateForConnectors(params: {\n    transactionRequest: TransactionRequest;\n    connectorOptions: AccountSendTxParams;\n  }): Promise<{\n    transactionRequest: TransactionRequest;\n    connectorsSendTxParams: FuelConnectorSendTxParams;\n  }> {\n    const { transactionRequest: requestToPrepare, connectorOptions } = params;\n\n    const { onBeforeSend, skipCustomFee = false } = connectorOptions;\n","sourceCodeStart":1261,"sourceCodeEnd":1297,"githubUrl":"https://github.com/FuelLabs/fuels-ts/blob/b3f37c91aca4aa9d5e4c0d3967f66237190826ea/packages/account/src/account.ts#L1261-L1297","documentation":"Thrown by validateConsolidationTxsCoins when the coins array contains UTXOs whose assetId does not match the assetId being consolidated. Consolidation builds one transaction against a single asset, so any foreign-asset coin would corrupt the output accounting. This guard runs in both the base-asset and non-base-asset assembly paths.","triggerScenarios":"Passing a coins array (or letting getCoins fetch one) that mixes assetIds, then calling account.consolidateCoins({ assetId }) or account.assembleNonBaseAssetConsolidationTxs({ assetId, coins }) where not every coin.assetId === assetId.","commonSituations":"Fetching all coins for an address (no asset filter) and feeding them to consolidateCoins for a specific asset; mutating assetId mid-loop; off-by-one when slicing a cached coin list.","solutions":["Always fetch coins with the asset filter: provider.getCoins(account.address, assetId).","If using a cached list, filter it right before the call: coins.filter(c => c.assetId === assetId).","Group coins by assetId first and consolidate each group separately."],"exampleFix":"// before\nconst { coins } = await provider.getCoins(account.address);\nawait account.consolidateCoins({ assetId });\n\n// after\nconst { coins } = await provider.getCoins(account.address, assetId);\nawait account.consolidateCoins({ assetId });","handlingStrategy":"validation","validationCode":"// Always fetch coins with the asset filter so the array is homogeneous\nconst { coins } = await provider.getCoins(account.address, assetId);\nawait account.consolidateCoins({ assetId });\n\n// or sanitize an existing list:\nconst homogeneous = coins.filter(c => c.assetId === assetId);","typeGuard":"function allSameAsset(coins: Coin[], assetId: string): boolean {\n  return coins.every(c => c.assetId === assetId);\n}","tryCatchPattern":"try {\n  await account.consolidateCoins({ assetId });\n} catch (e) {\n  if (e instanceof FuelError && e.code === ErrorCode.COINS_ASSET_ID_MISMATCH) {\n    // re-fetch with the correct asset filter and retry\n  } else throw e;\n}","preventionTips":["Always pass the assetId filter to provider.getCoins when consolidating.","Filter cached coin lists by assetId immediately before use.","Group coins by assetId and consolidate each group separately."],"tags":["consolidation","utxo","asset-id","validation"],"backgroundTag":null,"analyzedSha":"b3f37c91aca4aa9d5e4c0d3967f66237190826ea","analyzedAt":"2026-08-12T20:30:56.448Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}