> For the complete documentation index, see [llms.txt](https://docs.ethernity.cloud/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.ethernity.cloud/developer-guide/the-guide/build-and-publish-your-first-dapp.md).

# Build & publish your first dApp

This is the full path from an empty folder to a confidential dApp registered on the network: scaffold, write a backend function, prove it locally, bake it into an enclave, publish. Every step uses one command, and nothing costs gas until the very last one.

Before starting, make sure your toolchain is ready — see [Environment Prerequisites](https://docs.ethernity.cloud/developer-guide/the-guide/environment-prerequisites).

### 1. Scaffold — `ecld-init`

Install the SDK and initialize the project. Python:

```sh
pip install ethernity-cloud-sdk-py
ecld-init
```

JavaScript:

```sh
npm install @ethernity-cloud/sdk-js
npx ecld-init
```

Answer the prompts: a project name (this becomes your enclave's on-chain name), the network (default **Bloxberg Testnet** — the right place to start), the service type, and whether to enable the **Enclave State Registry** (say yes if your dApp needs state that persists between tasks — see [Managing dApp State (ESR)](https://docs.ethernity.cloud/developer-guide/the-guide/managing-dapp-state-esr)).

This writes your project config and scaffolds `src/serverless/` — the code that will run inside the enclave.

### 2. Write your backend

Your dApp's functions live in `src/serverless/backend.py` (or `backend.js`). Every exported function becomes callable from a task payload — the string a client submits.

```python
# src/serverless/backend.py
def hello(msg="World"):
    return "Hello " + msg
```

```javascript
// src/serverless/backend.js
function hello(msg = 'World') {
  return 'Hello ' + msg;
}
module.exports = { hello };
```

Return plain data — it is encoded automatically (JSON for objects, text for strings, base64 for bytes). To attach persistent state to the result, return through `ecld_result(...)` — see the [ESR page](https://docs.ethernity.cloud/developer-guide/the-guide/managing-dapp-state-esr).

### 3. Prove the call locally — `ecld-test`

Before building anything, run your function with the enclave's own executor — instant, no SGX, no gas:

```sh
ecld-test 'hello("World")'
```

This catches wrong names, bad arguments, and broken imports **before** anything is paid for. If your backend uses ESR, the state registry is emulated locally, on by default. Full reference: [Running your dApp](https://docs.ethernity.cloud/developer-guide/the-guide/running-your-dapp).

### 4. Bake the enclave — `ecld-build`

```sh
ecld-build
```

This bakes your backend into the securelock enclave image (Docker required). It also refuses unsafe patterns — dynamic execution of task input — and, for ESR projects, fills in the correct registry contract for your network. The result is an attestable image whose measurement will be registered on-chain, so the network can verify a node runs your exact, untampered code.

### 5. Publish — `ecld-publish`

```sh
ecld-publish
```

This registers your enclaves in the on-chain Image Registry: certificates are extracted, the image goes to IPFS, and the registration transaction is paid by your wallet — so you need testnet tokens first: grab them free at the [Testnet Faucet](https://docs.ethernity.cloud/testnet/testnet-faucet).

Confirm it landed — free, read-only:

```sh
ecld-info
```

Both enclaves should show **published** and **validated** — see [Inspecting your dApp](https://docs.ethernity.cloud/developer-guide/the-guide/inspecting-your-dapp).

### 6. Run it on the network

```sh
ecld-run 'hello("World")'
```

Your code executes inside a real SGX enclave on a network node, and the decrypted result comes back to your terminal. From here:

* [Running your dApp](https://docs.ethernity.cloud/developer-guide/the-guide/running-your-dapp) — the full `ecld-test` / `ecld-run` reference
* [Managing dApp State (ESR)](https://docs.ethernity.cloud/developer-guide/the-guide/managing-dapp-state-esr) — give your dApp durable, encrypted state
* [Step-by-Step dApp](https://docs.ethernity.cloud/developer-guide/the-guide/step-by-step-dapp) — put a web frontend on what you just published
