SPED ECD Mapping Reference
Reference for SPED Escrituracao Contabil Digital (ECD) export, per IN RFB 2.003/2021.
Registro Map
| Registro | Block | Description | GL Source |
|---|---|---|---|
| 0000 | 0 | File header (company, period, CNPJ) | SPEDExportConfig |
| I010 | I | Identification (IND_ESC: G/R/A/B) | Config indEsc |
| I030 | I | Opening term (book identification) | Config + metadata |
| I050 | I | Chart of Accounts entries | gl_accounts (ACTIVE, with sped_natura) |
| I051 | I | Referential Chart mapping | gl_accounts.sped_referencial_code |
| I155 | I | Monthly balances per account | gl_account_balances by period |
| I200 | I | Journal entry headers | gl_journal_entries (POSTED only) |
| I250 | I | Journal entry line items | gl_journal_lines |
| 9999 | 9 | File close (total line count) | Computed |
SPED Natura Codes (COD_NAT)
Maps to gl_accounts.sped_natura:
| Code | Description | Account Types |
|---|---|---|
| 01 | Ativo (Assets) | ASSET |
| 02 | Passivo (Liabilities) | LIABILITY |
| 03 | Patrimonio Liquido (Equity) | EQUITY |
| 04 | Contas de Resultado (Result) | REVENUE, EXPENSE |
| 05 | Compensacao (Offsetting) | Special accounts |
| 09 | Outros (Other) | Uncategorized |
Default mapping in ACCOUNT_TYPE_SPED_NATURA:
- ASSET -> '01', LIABILITY -> '02', EQUITY -> '03', REVENUE -> '04', EXPENSE -> '04'
File Format
- Encoding: ISO-8859-1 (latin1)
- Delimiter: Pipe (
|) - Line terminator:
|\r\n - Date format: DDMMYYYY (e.g.,
15012026for Jan 15, 2026) - Number format: Brazilian notation with comma decimal (e.g.,
1234,56) - Hash: SHA-256 of the entire file buffer
Pre-Export Validation
The validateBeforeExport() function checks:
| Check | Registro | Failure Condition |
|---|---|---|
| CNPJ validity | 0000 | Invalid check digits |
| Balance verification | I155 | Any period has discrepancies |
| Unmapped accounts | I050 | ACTIVE non-header account with NULL sped_natura |
| Balance sheet equation | J100 | Assets != Liabilities + Equity |
CNPJ Validation
Full check-digit algorithm implemented in validateCNPJ():
- Strip non-digits, must be exactly 14 chars
- Reject uniform patterns (all same digit)
- Calculate first check digit with weights [5,4,3,2,9,8,7,6,5,4,3,2]
- Calculate second check digit with weights [6,5,4,3,2,9,8,7,6,5,4,3,2]
Account Indicators
| Field | Values |
|---|---|
| IND_CTA (I050) | S = Sintetica (header), A = Analitica (detail) |
| IND_DC_INI/FIN (I155) | D = Devedor (debit balance), C = Credor (credit balance) |
| IND_DC (I250) | D = Debito, C = Credito |
| IND_LCTO (I200) | N = Normal, E = Estorno (reversal), X = Extemporaneo |
Data Flow
gl_accounts ──────> I050 (Chart of Accounts)
└─> I051 (Referential mapping, if sped_referencial_code set)
gl_account_balances ──> I155 (Monthly balances per period)
gl_journal_entries ──> I200 (Entry headers, POSTED only)
└─ gl_journal_lines ──> I250 (Line items with D/C indicator)