Getting Started ​
The Nox Solidity library lets you write smart contracts that operate on encrypted data. You import the Nox library, use encrypted types like euint256 instead of uint256, and the protocol handles encryption and off-chain computation transparently.
How It Works ​
Working with confidential data in Solidity follows three steps:
Receive encrypted inputs: the user encrypts a value with the JS SDK and sends a handle + proof to your contract. You call
Nox.fromExternal()to validate the proof and get a typed encrypted handle.Compute on encrypted data: use
Nox.add(),Nox.sub(),Nox.eq(),Nox.select(), etc. These functions emit events that trigger off-chain TEE computation. The result is a new encrypted handle.Manage access: grant permissions with
Nox.allow()so handles can be reused in future transactions, andNox.addViewer()so users can decrypt results off-chain via the JS SDK.
INFO
Operations on encrypted handles are not executed on-chain. The contract emits events, and the off-chain Runner performs the actual computation asynchronously inside a TEE enclave. The encrypted result is stored in the Handle Gateway under the deterministic handle computed on-chain.
Prerequisites ​
- Solidity ^0.8.0
- Hardhat 3 or Foundry
- Node.js 18+ with
npm,yarn,pnpm, orbun
Installation ​
npm install @iexec-nox/nox-protocol-contractsyarn add @iexec-nox/nox-protocol-contractspnpm add @iexec-nox/nox-protocol-contractsbun add @iexec-nox/nox-protocol-contractsThe encrypted-types package (providing euint256, ebool, etc.) is installed automatically as a dependency.
Imports ​
import {Nox, euint256, externalEuint256} from "@iexec-nox/nox-protocol-contracts/contracts/sdk/Nox.sol";Import the Nox library along with the encrypted types you need, all from a single path. The Nox.sol file re-exports every type from EncryptedTypes.sol, so there is no need for a separate import.
Encrypted Types ​
Encrypted types are custom defined value types backed by bytes32. Each type wraps a handle, a 32-byte identifier that references encrypted data stored off-chain in the Handle Gateway.
| Category | Types | Example |
|---|---|---|
| Boolean | ebool | Encrypted true/false |
| Unsigned integers | euint8, euint16, ..., euint256 | Encrypted balances, amounts |
| Signed integers | eint8, eint16, ..., eint256 | Encrypted signed values |
| Address | eaddress | Encrypted Ethereum address |
| Fixed bytes | ebytes1, ..., ebytes32 | Encrypted raw bytes |
Each type has a corresponding external* variant (e.g. externalEuint256) used for handles received from users that need proof validation before use.
Next Steps ​
- Arithmetic:
add,sub,mul,divwith wrapping semantics - Comparisons:
eq,ne,lt,le,gt,ge - Token Operations:
transfer,mint,burn - Access Control: permissions and viewer management
- JS SDK: encrypt inputs and decrypt results from JavaScript
