# Before You Build
Source: https://docs.chain.link/cre/getting-started/before-you-build-ts
Last Updated: 2026-02-04

> For the complete documentation index, see [llms.txt](/llms.txt).

You've completed the Getting Started guide and built a workflow that fetches offchain data, reads from a smart contract, performs calculations, and writes results onchain. You're ready to build your own workflows.

Before you do, take two minutes to understand how CRE differs from typical development. These tips will save you debugging time.

## Library compatibility

Your TypeScript code compiles to WebAssembly and runs in a QuickJS environment, **not Node.js**. Some NPM packages won't work if they rely on Node.js-specific APIs like `node:crypto` or `node:fs`.

**Before using a third-party package:**

1. Check if it relies on Node.js built-in modules
2. Test with `cre workflow simulate` — simulation uses the same WASM environment as production, so compatibility issues surface immediately

> **TIP: Cryptography libraries**
>
> If you need cryptographic functions, <a href="https://paulmillr.com/noble/" target="_blank" rel="noopener noreferrer">Noble</a> is a popular JavaScript cryptography library that works well with QuickJS. Always verify any third-party library in simulation before deploying.

> **TIP: Learn more**
>
> See [TypeScript Runtime Environment](/cre/concepts/typescript-wasm-runtime) for details on QuickJS compatibility and how to [verify library support](/cre/concepts/typescript-wasm-runtime#checking-library-compatibility).

## Working with Solidity integers

When sending values to smart contracts, always use `bigint` (with the `n` suffix) in your workflow code. JavaScript `number` loses precision for large values, causing **silent precision loss**.

```typescript
// WRONG - silent precision loss
const amount = 10000000000000001 // 10 quadrillion + 1
// Silently becomes 10000000000000000 (the +1 vanishes)

// CORRECT - use bigint
const amount = 10000000000000001n // Stays exactly 10000000000000001
```

> **TIP: Learn more**
>
> See [Writing Data Onchain](/cre/guides/workflow/using-evm-client/onchain-write/writing-data-onchain#step-2-abi-encode-your-value) for the complete Solidity-to-TypeScript type mapping.

## Safe decimal scaling

Smart contracts use fixed-point integers (e.g., 18 decimals for ERC-20 tokens). When converting between human-readable values and their onchain representations, avoid floating-point arithmetic — it causes **silent precision loss**.

Use <a href="https://viem.sh/docs/utilities/parseUnits" target="_blank">viem's `parseUnits()`</a> to scale up and <a href="https://viem.sh/docs/utilities/formatUnits" target="_blank">`formatUnits()`</a> to scale down. Both operate on strings, so no floating-point math is involved.

### Scaling up (human-readable to onchain)

```typescript
import { parseUnits } from "viem"

// WRONG - floating-point precision loss
const amount = BigInt(0.1 * 1e18)
// Result: 99999999999999984n (off by 16)

// CORRECT - string-based, no precision loss
const amount = parseUnits("0.1", 18)
// Result: 100000000000000000n (exact)
```

### Scaling down (onchain to human-readable)

```typescript
import { formatUnits } from "viem"

// WRONG - precision loss for large bigints
const display = Number(totalSupply) / 1e18

// CORRECT - string-based, no precision loss
const display = formatUnits(totalSupply, 18)
// Returns "1.5" for 1500000000000000000n
```

> **TIP: Works with any decimal count**
>
> Both functions accept any decimal count, not just 18. For example, USDC uses 6 decimals: `parseUnits("100.50", 6)` returns `100500000n`.

## Working with time

If your workflow uses timestamps (e.g., for API authentication or time-based queries), use `runtime.now()` instead of `Date.now()`. This ensures all nodes in the DON use the same timestamp and can reach consensus.

> **TIP: Learn more**
>
> See [Using Time in Workflows](/cre/guides/workflow/time-in-workflows) for details on DON time and best practices.

> **NOTE: Going deeper**
>
> These are the most common cases. For a complete guide to non-determinism (object iteration, Promise handling, and more), see [Avoiding Non-Determinism in Workflows](/cre/concepts/non-determinism).

## What's next?

Here are resources to help you go from simulation to production.

### Learn from examples

- **[Run the Custom Data Feed Demo](/cre/templates/running-demo-workflow)** — A starter template you can run locally and customize
- **[Browse all Templates](/cre/templates)** — Building blocks for specific patterns (secrets, HTTP auth, streams) and starter templates
- **[AI-Powered Prediction Market](/cre/demos/prediction-market)** — Full end-to-end demo integrating CRE with Gemini AI and Firebase

### Deploy to production

> **NOTE: Deployment access required**
>
> Deploying requires Early Access approval. Run `cre account access` or visit <a href="https://app.chain.link/cre/request-access" target="_blank">app.chain.link/cre/request-access</a> to submit a request. See [Requesting Deploy Access](/cre/account/deploy-access). While you wait, continue building and simulating workflows.

1. **[Link a Wallet Key](/cre/organization/linking-keys)** — Connect your wallet to your organization
2. **[Deploy Your Workflow](/cre/guides/operations/deploying-workflows)** — Push your workflow live
3. **[Monitor Your Workflow](/cre/guides/operations/monitoring-workflows)** — Watch it execute and debug issues

### Explore different triggers

You used a Cron trigger. Most production workflows react to events:

- **[HTTP Trigger](/cre/guides/workflow/using-triggers/http-trigger/overview)** — Trigger via API calls
- **[EVM Log Trigger](/cre/guides/workflow/using-triggers/evm-log-trigger)** — React to onchain events

### Add secrets

Real workflows need API keys and sensitive data:

- **[Using Secrets in Simulation](/cre/guides/workflow/secrets/using-secrets-simulation)** — Local development
- **[Using Secrets with Deployed Workflows](/cre/guides/workflow/secrets/using-secrets-deployed)** — Store secrets in the Vault DON for production
- **[Managing Secrets with 1Password](/cre/guides/workflow/secrets/managing-secrets-1password)** — Best practice: inject secrets at runtime

### Build your own consumer contract

- **[Building Consumer Contracts](/cre/guides/workflow/using-evm-client/onchain-write/building-consumer-contracts)** — Create contracts that receive CRE data

## Reference

Dive deeper into concepts from this guide:

| Topic                    | Resources                                                                                                                                                                                                                |
| ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| **Workflow structure**   | [Core SDK](/cre/reference/sdk/core), [Triggers Overview](/cre/guides/workflow/using-triggers/overview)                                                                                                                   |
| **HTTP & offchain data** | [API Interactions](/cre/guides/workflow/using-http-client), [Consensus & Aggregation](/cre/reference/sdk/consensus)                                                                                                      |
| **EVM interactions**     | [EVM Client Overview](/cre/guides/workflow/using-evm-client/overview), [Onchain Read](/cre/guides/workflow/using-evm-client/onchain-read), [Onchain Write](/cre/guides/workflow/using-evm-client/onchain-write/overview) |
| **Configuration**        | [Project Configuration](/cre/reference/project-configuration), [Secrets Guide](/cre/guides/workflow/secrets)                                                                                                             |
| **All capabilities**     | [Capabilities Overview](/cre/capabilities)                                                                                                                                                                               |