Build Your First Extension
This guide builds your first Flare Confidential Compute (FCC) extension from the template in the FCE Go scaffold.
You deploy it to Coston2 with fce, the FCC extension CLI, then run a test machine and send it work.
For background on FCC and Flare Compute Extensions (FCE), see the FCC overview.
A Go program that runs inside a Trusted Execution Environment (TEE) image, next to tee-node, plus the Solidity contract that sends it instructions.
The template has one operation on each channel: an instruction that a caller sends through your contract onchain, and a direct action that a client posts straight to the TEE's proxy.
FCC is in the final stages of development, and the scaffold and fce are still evolving.
Use Coston2 for everything in this guide, and expect interfaces to change.
How an Extension Works
An extension never talks to the chain directly.
It runs in one image with tee-node, which holds the TEE's key, talks to the outside world, and signs every result.
tee-node pulls work from tee-proxy, a public server that queues actions and stores results.
Work reaches the extension in one of two ways:
Instructions only reach the TEE after data providers sign them with more than 50% of the signing policy's weight. See Data providers and cosigners and TEE public and private keys.
You write two things: the handlers in Go, and the entrypoint contract in Solidity.
The scaffold's library handles the HTTP wiring to tee-node, strict payload decoding, and calls to the TEE key.
The shared ExtensionBase contract handles sending, fees, and checking TEE signatures.
Prerequisites
- Go 1.27.4 or newer, and
gccfor the tests that run with cgo. - Foundry 1.7.1 or newer (
forge,cast). - Docker with buildx and Compose.
The stack runs as
linux/amd64. On Apple Silicon, Docker emulates it, which is slow but fine for a test machine. - A Coston2 account funded from the Coston2 faucet. It pays for gas, extension registration, and machine registration and availability check fees.
fce signs transactions with the keystore you give it, and the make targets build and run code.
Use a key that holds only test funds.
Install the scaffold and fce only from the flare-foundation GitHub organization.
Step 1: Install fce Tooling
Clone the tooling repository and install the CLI:
git clone https://github.com/flare-foundation/fce-tooling.git
cd fce-tooling
go install ./cmd/fce
fce version
go install puts fce in GOBIN, or GOPATH/bin if GOBIN is unset, so keep that directory on your PATH.
A build from a release tag with no local changes reports that version.
Any other build is a development build, and fce prints a warning when it uses one.
Step 2: Fork the Scaffold
Fork fce-go-scaffold on GitHub, then clone your fork:
git clone https://github.com/<your-account>/fce-go-scaffold.git
cd fce-go-scaffold
Your fork changes only template/ (and examples/, if you build on one).
Leave the shared parts alone: pkg/, sol/, conformance/, internal/, launcher/, docs/, fce-version, the Makefile, and the lint and agent files.
You get fixes to those by merging upstream, and local edits there cause merge conflicts.
The scaffold's forking guide covers optional renames, such as the Go module path.
Step 3: Import Your Deployer Key
fce signs with a key from a Foundry keystore, so the private key never appears in a command argument or an environment variable.
Import your funded Coston2 key once:
cast wallet import coston2-deployer --interactive
cast wallet address --account coston2-deployer
This guide uses coston2-deployer as the account name.
fce asks for the keystore password each time it signs, or reads it from a file passed with -password-file.
Template Layout
| Path | What it is |
|---|---|
template/cmd/extension/main.go | The entrypoint: reads the environment, registers ops, serves |
template/internal/app/ | Your code: op constants, handlers, state, and their tests |
template/conformance/ | Golden fixtures for your ops, generated from the Go tests |
template/contracts/ | The entrypoint contract, its deploy scripts, and its forge tests |
template/Dockerfile | The reproducible TEE image: launcher, tee-node, and extension |
The template's operations:
| Operation type | Operation command | Channel | Payload | Result |
|---|---|---|---|---|
MY_EXTENSION | MY_COMMAND | Instruction | abi.encode(address sender, bytes message) | The same pair, ABI-encoded |
MY_EXTENSION | MY_DIRECT_COMMAND | Direct | JSON {"message": "…"} | The same JSON |
Entrypoint Go Code
main.go reads the environment that the launcher passes in, registers the handlers, and serves tee-node until it is stopped.
Read your own environment variables where the TODO is.
View main.go
// Command extension serves tee-node's calls to the extension until it is stopped.
package main
import (
"context"
"fmt"
"os"
"os/signal"
"syscall"
"github.com/flare-foundation/fce-go-scaffold/pkg/extension"
"github.com/flare-foundation/fce-go-scaffold/template/internal/app"
"github.com/flare-foundation/go-flare-common/pkg/logger"
)
func main() {
if err := run(); err != nil {
logger.Fatalf("%v", err)
}
}
func run() error {
env, err := extension.ReadEnv()
if err != nil {
return fmt.Errorf("reading the environment: %w", err)
}
logger.Set(logger.Config{Level: env.LogLevel})
// TODO: read your own variables here, and list each in the Dockerfile's
// launch-policy label and the launcher's --env.
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGTERM, os.Interrupt)
defer stop()
srv := extension.New(extension.WithSignPort(env.SignPort))
app.Register(srv)
return srv.ListenAndServe(ctx, env.ExtensionPort)
}
Operations and Registration
An operation is a pair: an operation type, which groups commands, and an operation command, which is a verb. Each pair belongs to exactly one channel, either instruction or direct, never both.
View app.go
// Package app is the extension's own code: its ops, handlers and state.
//
// TODO: replace the placeholder op with your extension's ops.
package app
import (
"github.com/flare-foundation/fce-go-scaffold/pkg/extension"
"github.com/flare-foundation/go-flare-common/pkg/tee/op"
)
// The extension's op pairs. Each pair belongs to one channel, instructions or
// direct actions, never both; an op type may have commands on both.
const (
// OPTypeMyExtension names the extension. TODO: rename it.
OPTypeMyExtension op.Type = "MY_EXTENSION"
// OPCommandMyCommand arrives as an instruction, sent through the contract.
OPCommandMyCommand op.Command = "MY_COMMAND"
// OPCommandMyDirectCommand arrives as a direct action, posted to the proxy.
OPCommandMyDirectCommand op.Command = "MY_DIRECT_COMMAND"
)
// Register registers the extension's handlers on s.
func Register(s *extension.Server) {
s.RegisterInstructionHandler(OPTypeMyExtension, OPCommandMyCommand, myCommand)
s.RegisterDirectHandler(OPTypeMyExtension, OPCommandMyDirectCommand, myDirectCommand)
}
Registration panics on a mistake: a pair registered twice, an operation type that starts with F_ (reserved for Flare system operations), or a name longer than 32 bytes.
Instruction Operation Handler
tee-node does not pass the caller's address to the extension.
If you need it, your contract has to encode msg.sender into the payload, which is what the template does.
View mycommand.go
package app
import (
"context"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
"github.com/flare-foundation/fce-go-scaffold/pkg/extension"
"github.com/flare-foundation/fce-go-scaffold/pkg/payload"
"github.com/flare-foundation/go-flare-common/pkg/tee/instruction"
)
// errNoMessage refuses an empty message, on both channels.
var errNoMessage = extension.PublicError("message required", nil)
// myCommandArgs is abi.encode(sender, message), as the contract builds it;
// names map to myCommandPayload's fields.
var myCommandArgs = abi.Arguments{
{Name: "sender", Type: abiType("address")},
{Name: "message", Type: abiType("bytes")},
}
// myCommandPayload carries the caller: tee-node doesn't pass it, so the contract encodes msg.sender.
type myCommandPayload struct {
Sender common.Address
Message []byte
}
// myCommand echoes the sender and the message back, ABI-encoded.
//
// TODO: replace it with your command. tee-node doesn't remember instructions,
// so one can arrive again, or after a newer one: keep it idempotent, as this
// echo is, or refuse replays; where order matters, have the contract number
// them, as examples/direct's setAdmin does.
func myCommand(_ context.Context, i *instruction.DataFixed) ([]byte, extension.Run, error) {
var p myCommandPayload
if err := payload.DecodeABI(myCommandArgs, i.OriginalMessage, &p); err != nil {
return nil, nil, extension.PublicError("invalid payload", err)
}
if len(p.Message) == 0 {
return nil, nil, errNoMessage
}
out, err := myCommandArgs.Pack(p.Sender, p.Message)
if err != nil {
return nil, nil, extension.PublicError("encoding the result", err)
}
return out, nil, nil
}
func abiType(t string) abi.Type {
typ, err := abi.NewType(t, "", nil)
if err != nil {
panic(err)
}
return typ
}
A handler returns one of three things:
| It returns | The action gets |
|---|---|
| An error | status 0 at once, with error: <text> as the public log |
| Data | status 1 at once |
Data and a Run | status 2 (pending) at once, then the Run continues in the background |
A handler has 1.5 seconds to answer; tee-node waits 2 seconds in total.
Anything slower needs the long-running mode, which the External API guide shows.
Wrap any error that could carry a secret in extension.PublicError("...", err).
Only the first argument reaches the public log.
tee-node does not remember instructions.
An operator can deliver one again, or deliver it after a newer one.
Make each handler idempotent or reject replays.
When order matters, number the instructions in the contract, as the Direct Actions guide does.
Direct Action Handler
A direct action reaches the extension only through the proxy. There is no fee and no data provider signature, so nothing vouches for the sender.
View mydirectcommand.go
package app
import (
"context"
"encoding/json"
"github.com/flare-foundation/fce-go-scaffold/pkg/extension"
"github.com/flare-foundation/fce-go-scaffold/pkg/payload"
"github.com/flare-foundation/tee-node/pkg/types"
)
// myDirectCommandMessage is the JSON a client posts to the proxy's /direct, and the result.
type myDirectCommandMessage struct {
Message string `json:"message"`
}
// myDirectCommand echoes the message back as JSON.
//
// TODO: decide who may trigger it. Anyone holding the proxy's API key can, and
// the handler can't tell who did: check an authorization the payload carries.
// Anyone who saw it can send it again, so keep it idempotent, as this echo is,
// or refuse replays, as examples/direct does.
func myDirectCommand(_ context.Context, d *types.DirectInstruction) ([]byte, extension.Run, error) {
var m myDirectCommandMessage
if err := payload.DecodeJSON(d.Message, &m); err != nil {
return nil, nil, extension.PublicError("invalid payload", err)
}
if m.Message == "" {
return nil, nil, errNoMessage
}
out, err := json.Marshal(m)
if err != nil {
return nil, nil, extension.PublicError("encoding the result", err)
}
return out, nil, nil
}
Decode payloads with pkg/payload.
payload.DecodeABI accepts only the canonical ABI encoding, and payload.DecodeJSON rejects unknown fields and trailing data.
Entrypoint Contract
The InstructionSender contract is the only onchain entry point for your instructions.
It inherits ExtensionBase, which binds the extension ID, charges fees, sends instructions through FlareTeeManager, and checks TEE signatures.
View InstructionSender.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
import { ExtensionBase } from "fcc-extension-scaffold/src/ExtensionBase.sol";
/// @title InstructionSender
/// @notice The extension's entrypoint contract: it sends the extension's instructions to its
/// TEE machines.
/// @dev NOTE: the deployer owns this contract, with the project fee and its withdrawal, and,
/// through fce deploy, the extension in the registry, which decides what code its machines run.
/// Secure that key, or move both (for example to a multisig), before production.
/// TODO: replace the placeholder command with your extension's.
contract InstructionSender is ExtensionBase {
/// @notice The extension's op type, the Go side's OPTypeMyExtension.
// forge-lint: disable-next-line(unsafe-typecast)
bytes32 public constant OP_TYPE_MY_EXTENSION = bytes32("MY_EXTENSION");
/// @notice MY_COMMAND, the Go side's OPCommandMyCommand.
// forge-lint: disable-next-line(unsafe-typecast)
bytes32 public constant OP_COMMAND_MY_COMMAND = bytes32("MY_COMMAND");
/// @param _flareTeeManager The FlareTeeManager diamond's address.
constructor(address _flareTeeManager) ExtensionBase(_flareTeeManager) { }
/// @notice Sends MY_COMMAND with `_message`. Pay at least
/// quoteFee(OP_TYPE_MY_EXTENSION, OP_COMMAND_MY_COMMAND); the contract keeps any excess.
/// @dev The payload carries the caller: tee-node doesn't pass it to the extension.
function myCommand(bytes calldata _message) external payable chargesFees returns (bytes32) {
return _send(OP_TYPE_MY_EXTENSION, OP_COMMAND_MY_COMMAND, abi.encode(msg.sender, _message));
}
}
- Solidity's
bytes32("MY_EXTENSION")and Go'sop.Type("MY_EXTENSION").Hash()produce the same bytes, so the names must match exactly. - Write one payable send function per instruction command and add the
chargesFeesmodifier to it. - Direct commands have no function in the contract. Clients post them to the proxy instead.
View ExtensionBase.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
import { Ownable, Ownable2Step } from "@openzeppelin-contracts/access/Ownable2Step.sol";
import { ECDSA } from "@openzeppelin-contracts/utils/cryptography/ECDSA.sol";
import { MessageHashUtils } from "@openzeppelin-contracts/utils/cryptography/MessageHashUtils.sol";
import { IExtensionManager } from "flare-periphery/src/coston2/IExtensionManager.sol";
import { IInstructions } from "flare-periphery/src/coston2/IInstructions.sol";
import { IMachineEmergencyPause } from "flare-periphery/src/coston2/IMachineEmergencyPause.sol";
import { IMachineManager } from "flare-periphery/src/coston2/IMachineManager.sol";
import { IOperationFees } from "flare-periphery/src/coston2/IOperationFees.sol";
/// @title ExtensionBase
/// @notice The base of an extension's entrypoint contract: it binds the contract to its
/// extension id, sends instructions to the extension's TEE machines for the protocol fee plus
/// an optional project fee, keeps any excess for the owner to withdraw, and checks a TEE's
/// signature.
/// @dev A shared part of the scaffold: forks leave it unchanged and merge fixes from upstream.
abstract contract ExtensionBase is Ownable2Step {
/// @notice The FlareTeeManager diamond, which serves every TEE facet.
address public immutable flareTeeManager;
/// @notice The extension id, set once by setExtensionId; 0 until then.
uint256 public extensionId;
/// @notice What the contract keeps per instruction, on top of the protocol fee.
uint256 public projectFee;
// set by chargesFees for the function it wraps: what is left of msg.value
bool private transient charging;
uint256 private transient budget;
event ExtensionIdSet(uint256 extensionId);
event ProjectFeeSet(uint256 projectFee);
event Withdrawn(address indexed to, uint256 amount);
error NoCode(address account);
error ExtensionIdAlreadySet(uint256 extensionId);
error NotInstructionsSender(uint256 extensionId);
error ExtensionIdNotSet();
error InsufficientFee(uint256 price, uint256 available);
error DuplicateTee(address teeId);
error NotCharging();
error NestedCharge();
error WithdrawFailed();
error SignerNotExtensionTee(address signer);
error SignerNotInProduction(address signer);
error ExtensionEmergencyPaused();
/// @notice Lets a function send instructions: msg.value pays for every _send it makes, and
/// the contract keeps what they leave, with the project fees. Every function that calls _send
/// needs it; it can't be nested.
modifier chargesFees() {
require(!charging, NestedCharge());
charging = true;
budget = msg.value;
_;
// transient storage lasts the whole transaction, not just this call
charging = false;
budget = 0;
}
/// @param _flareTeeManager The FlareTeeManager diamond's address.
constructor(address _flareTeeManager) Ownable(msg.sender) {
require(_flareTeeManager.code.length > 0, NoCode(_flareTeeManager));
flareTeeManager = _flareTeeManager;
}
/// @notice Binds the contract to its extension id, once, and only an id whose registered
/// instructions sender is this contract. Owner only: anyone may register an extension naming
/// this contract, and binding theirs would hand it their machines.
/// @param _id The id ExtensionManager.register returned.
function setExtensionId(uint256 _id) external onlyOwner {
require(extensionId == 0, ExtensionIdAlreadySet(extensionId));
require(
IExtensionManager(flareTeeManager).getTeeExtensionInstructionsSender(_id) == address(this),
NotInstructionsSender(_id)
);
extensionId = _id;
emit ExtensionIdSet(_id);
}
/// @notice Sets the project fee; 0 charges only the protocol fee.
function setProjectFee(uint256 _fee) external onlyOwner {
projectFee = _fee;
emit ProjectFeeSet(_fee);
}
/// @notice Sends the contract's whole balance, the collected project fees and any excess
/// callers paid, to `_to`.
function withdraw(address payable _to) external onlyOwner {
uint256 amount = address(this).balance;
emit Withdrawn(_to, amount);
(bool ok,) = _to.call{ value: amount }("");
require(ok, WithdrawFailed());
}
/// @notice The price of one instruction to one TEE: the protocol fee plus projectFee.
/// A send must pay at least this; the contract keeps any excess.
function quoteFee(bytes32 _opType, bytes32 _opCommand) public view returns (uint256) {
return _protocolFee(_opType, _opCommand, _randomTee()) + projectFee;
}
/// @dev Sends `_message` as _opType / _opCommand to one random TEE of the extension, with
/// no cosigners and the caller as claim-back address.
function _send(bytes32 _opType, bytes32 _opCommand, bytes memory _message) internal returns (bytes32) {
return _send(_randomTee(), _opType, _opCommand, _message);
}
/// @dev Sends `_message` as _opType / _opCommand to `_teeIds`, which must be distinct, with no
/// cosigners and the caller as claim-back address.
function _send(address[] memory _teeIds, bytes32 _opType, bytes32 _opCommand, bytes memory _message)
internal
returns (bytes32)
{
return _send(
_teeIds,
IInstructions.TeeInstructionParams({
opType: _opType,
opCommand: _opCommand,
message: _message,
cosigners: new address[](0),
cosignersThreshold: 0,
claimBackAddress: msg.sender
})
);
}
/// @dev Sends an instruction with explicit TEEs and parameters, inside a chargesFees
/// function. It takes the price for those TEEs from what is left of msg.value, forwards
/// exactly the protocol fee and keeps projectFee. The TEEs must be distinct.
function _send(address[] memory _teeIds, IInstructions.TeeInstructionParams memory _params)
internal
returns (bytes32)
{
require(charging, NotCharging());
// the platform charges a repeated TEE once but keeps all it is sent
for (uint256 i = 1; i < _teeIds.length; ++i) {
for (uint256 j; j < i; ++j) {
require(_teeIds[i] != _teeIds[j], DuplicateTee(_teeIds[i]));
}
}
uint256 protocolFee = _protocolFee(_params.opType, _params.opCommand, _teeIds);
uint256 price = protocolFee + projectFee;
require(budget >= price, InsufficientFee(price, budget));
budget -= price;
// sendInstructions keeps all it is sent
return IInstructions(flareTeeManager).sendInstructions{ value: protocolFee }(_teeIds, _params);
}
function _protocolFee(bytes32 _opType, bytes32 _opCommand, address[] memory _teeIds)
internal
view
returns (uint256)
{
return IOperationFees(flareTeeManager).calculateFeeByTeeIds(_opType, _opCommand, _teeIds);
}
function _randomTee() internal view returns (address[] memory) {
require(extensionId != 0, ExtensionIdNotSet());
return IMachineManager(flareTeeManager).getRandomTeeIds(extensionId, 1);
}
/// @dev The TEE that signed `_digest`, the keccak256 of a message the extension signed through
/// tee-node's sign port (EIP-191), refusing any signer that isn't a production TEE of this
/// extension, or while the extension is emergency-paused.
function _teeSigner(bytes32 _digest, bytes memory _signature) internal view returns (address _teeId) {
_teeId = ECDSA.recover(MessageHashUtils.toEthSignedMessageHash(_digest), _signature);
require(
!IMachineEmergencyPause(flareTeeManager).isExtensionEmergencyPaused(extensionId), ExtensionEmergencyPaused()
);
// an unknown signer reverts here, with the registry's TeeNotFound
require(IMachineManager(flareTeeManager).getExtensionId(_teeId) == extensionId, SignerNotExtensionTee(_teeId));
require(
IMachineManager(flareTeeManager).getTeeMachineStatus(_teeId) == IMachineManager.TeeStatus.PRODUCTION,
SignerNotInProduction(_teeId)
);
}
}
The price of an instruction is the protocol fee, which governance sets per operation pair and charges per TEE, plus an optional project fee, which the contract owner sets with setProjectFee.
quoteFee(opType, opCommand) returns the price for one TEE.
The deploy script finds FlareTeeManager in the Flare contract registry, so no address is hardcoded:
View Deploy.s.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
import { IFlareContractRegistry } from "flare-periphery/src/coston2/IFlareContractRegistry.sol";
import { Script } from "forge-std/src/Script.sol";
import { InstructionSender } from "../src/InstructionSender.sol";
/// @title Deploy
/// @notice Deploys the extension's contracts and writes their addresses, as JSON, to
/// DEPLOY_OUTPUT, a path under deployments/: forge may write only there, and creates only
/// deployments/ itself.
/// FLARE_TEE_MANAGER overrides the FlareTeeManager address found in Flare's contract
/// registry; a chain without the registry, such as anvil, needs it.
contract Deploy is Script {
/// @notice Flare's contract registry, at the same address on every Flare network.
IFlareContractRegistry public constant REGISTRY =
IFlareContractRegistry(0xaD67FE66660Fb8dFE9d6b1b4240d8650e30F6019);
function run() external {
address manager = vm.envOr("FLARE_TEE_MANAGER", address(0));
if (manager == address(0)) {
manager = REGISTRY.getContractAddressByName("FlareTeeManager");
}
vm.startBroadcast();
InstructionSender sender = deploy(manager);
vm.stopBroadcast();
vm.createDir("deployments", true);
vm.writeJson(vm.serializeAddress("deploy", "instructionSender", address(sender)), vm.envString("DEPLOY_OUTPUT"));
}
/// @notice Deploys the contracts against the FlareTeeManager at `_manager`.
function deploy(address _manager) public returns (InstructionSender) {
return new InstructionSender(_manager);
}
}
Step 4: Test Locally
Run the Go handler tests, then check the extension from the outside with fce conformance command:
go test ./template/...
fce conformance ./template
fce conformance builds the binary as the image does and starts it against a fake sign port.
It then sends each fixture in template/conformance/ the way tee-node would, and runs the checks every extension must pass.
make test also runs the contract's forge tests.
The forge tests read the same my-command.json fixture, so the contract and the handler cannot drift apart.
fce image-check ./template builds the image and checks its Dockerfile, its config, and the binaries it runs, then does a smoke run.
Step 5: Deploy and Register
fce deploy -chain coston2 -account coston2-deployer ./template
fce deploy does four things:
- Deploys
InstructionSendersmart contract withcontracts/script/Deploy.s.solscript. - Registers it with
FlareTeeManager(ExtensionManager.register), which returns your extension ID. - Allows the deployer to own the extension's machines.
- Runs
contracts/script/PostRegister.s.solscript, which callssetExtensionIdon the contract.
It records the result in template/deployments/coston2.json: the chain, FlareTeeManager, your contract addresses, the extension ID, and everything later commands add.
Commit this file, because it publishes your extension's addresses alongside its code.
If you run fce deploy again, it finishes any remaining steps and does nothing once they're all done.
The deployer ends up owning both the contract (project fee, withdrawals) and the extension in the registry.
Registry ownership matters more: it decides which code hashes the extension's machines can run.
Before production, secure that key or move both roles to a multisig.
register succeeds when the deployer is an allowed extension owner, or when allExtensionOwnersAllowed() is true.
fce deploy then allowlists that account as a machine owner.
See Owner allowlists.
Step 6: Allow a Test Version and Set Governance
A test machine runs tee-node in test mode, so the extension must allow tee-node's fixed test code hash.
It also needs governance: the signers that govern its machines.
For a test, use your deployer address as the only signer:
fce add-version -chain coston2 -account coston2-deployer -test ./template
fce governance -chain coston2 -account coston2-deployer \
-signers "$(cast wallet address --account coston2-deployer)" -threshold 1 ./template
fce status -chain coston2 ./template
fce status compares your deployment record with the chain.
Test machines have no TEE, and their operators hold their keys, yet contracts accept their signatures as the extension's.
Only allow the test version on an extension that real users don't use.
Otherwise, disable it with fce disable-version -test before users arrive.
Disabling is permanent.
Step 7: Run a Test Machine
fce run -chain coston2 -account coston2-deployer ./template
fce run takes a machine from nothing to production:
-
Checks the chain, builds the image with
make image, and startstee-node,tee-proxy, and Redis with Docker Compose. -
Opens a Cloudflare quick tunnel so data providers and the availability check can reach the proxy. Use
-urlto provide your own public URL instead. -
Registers the machine, which attests to a challenge from the chain, and waits for the attestation result.
-
Asks one of the system's machines to check that yours is available.
-
Moves the machine to production and prints a line like this:
machine 0x… of extension <id> is in production at https://….trycloudflare.com
Registration and the availability check charge fees, and each step pays gas.
Each start of tee-node generates a new key, so each run registers a new machine.
By default, tee-proxy reads signing policies and voters through Coston2's public RPC.
That is fine for a test machine, but the proxy then trusts the RPC's answers.
To read them from a Flare C-chain indexer database instead, pass -indexer-db with a TOML file containing host, port, database, username, and password.
fce run stays attached and shows the logs.
Use -detach to return once the machine is in production, then stop it later with fce stop.
Step 8: Send an Instruction and a Direct Action
From a second terminal, send MY_COMMAND through your contract with the message hello:
fce send -chain coston2 -account coston2-deployer ./template 'myCommand(bytes)' 0x68656c6c6f
fce send finds the fee by simulating the call, sends the transaction, then polls the proxy of each TEE the instruction went to.
It checks both the TEE's and the proxy's signatures and prints the result:
instruction 0x…: MY_EXTENSION MY_COMMAND
status 1 (ok), … after sending
data 0x…
The data is abi.encode(sender, message), which echoes your address and hello.
Post MY_DIRECT_COMMAND with {"message":"hello"} as hex:
fce direct -chain coston2 ./template MY_EXTENSION MY_DIRECT_COMMAND 0x7b226d657373616765223a2268656c6c6f227d
fce direct uses the proxy API key that fce run generated.
To post a direct action yourself, send POST /direct to the proxy with the API key in an X-Api-Key header:
{
"opType": "0x4d595f455854454e53494f4e0000000000000000000000000000000000000000",
"opCommand": "0x4d595f4449524543545f434f4d4d414e44000000000000000000000000000000",
"message": "0x7b226d657373616765223a2268656c6c6f227d"
}
The op type and command are bytes32 names, and the message is hex.
Read the result at GET /action/result/<id>?submissionTag=submit.
Step 9: Stop the Machine
Press Ctrl-C in the fce run terminal.
fce pauses the machine onchain and then removes the stack.
Pausing comes first because a machine stays in production after it stops running, and sends would keep going to it.
If pausing fails, fce keeps the run's state, and fce stop tries again.
fce run refuses to start a new machine until the old one is paused.
Make It Your Own
- Rename the op.
Pick op type and command names for your own domain.
Do not use the
F_prefix or reuse a system command name (see reserved names). Change the constants inapp.goand thebytes32constants inInstructionSender.soltogether. - Write the handler.
Decode strictly, validate everything before the first write, and synchronize shared state yourself.
The library does not serialize calls, so an instruction, a direct action, and
GET /statecan all run at once. - Add a send function with
chargesFeesfor each instruction command. - Regenerate the fixtures with
go test ./template/internal/app -update, then runmake testandfce conformance ./template. - Name the image.
Set
org.opencontainers.image.titleandorg.opencontainers.image.versionintemplate/Dockerfile. The version label is part of the image hash. - Redeploy the code.
Each
fce runbuilds the image again, so a new run picks up your changes.
The scaffold's extension guide covers errors, long-running jobs, state, the TEE key, wallet keys, and your own environment variables in depth. The rules list every requirement an extension must meet, with what enforces it.
The scaffold's library is Go, but the wire protocol between tee-node and the extension is language-agnostic.
The extension contract defines it, and fce conformance [flags] -- command [args...] checks any binary against it.
Going to Production
Test machines are for development.
A production machine runs the attested image on a Confidential Space VM (GCP_AMD_SEV or GCP_INTEL_TDX):
fce add-version -chain coston2 -account coston2-deployer -platform GCP_AMD_SEV,GCP_INTEL_TDX ./template
fce add-version builds the image reproducibly and allows its config digest, under the image's version label, on the platforms you name.
Commit your changes first so that anyone can rebuild the same hash from your fork.
List every platform you will use now: you cannot add a platform to a hash later, so adding one means bumping the version label.
fce registers test machines.
Deploy a TEE on Google Cloud starts the same image on a Confidential Space VM, with tee-proxy and a C-chain indexer, and registers that machine on FlareTeeManager.
Try continue building with Flare Confidential Compute follow these guides:
- Deploy a TEE on Google Cloud: run the allowed image on a Confidential Space VM with tee-proxy and a C-chain indexer.
- External API Extension: call web APIs over TLS, return partial results past the 2-second limit, and verify a TEE-signed price onchain.
- Direct Actions Extension: provision secrets encrypted to the TEE, protect against replays, run a sealed-bid auction, and report state that a contract verifies.
- Wallets Extension: sign EVM transactions with wallet keys that
tee-nodegenerates and keeps inside the TEE. - FCC Troubleshooting: common
fceand machine issues.