Skip to main content

Network Templates

Export, share, and import complete network configurations as portable templates. Templates capture everything needed to recreate a network: organizations, nodes, channels, policies, and chaincode definitions.

Overview​

Network templates use a variable system (${varName.property}) to make configurations portable. When you export a network, concrete values (org IDs, node IDs, key IDs) are replaced with variables. When you import, you map those variables to resources on the target instance.

Supported platforms:

  • Fabric — organizations, peers, orderers, channels, policies, consensus (etcdraft/smartbft), chaincode definitions
  • Besu — validator keys, consensus config (QBFT), genesis parameters, alloc, smart contract definitions (ABI + bytecode)

Export a Network​

Via API​

curl http://localhost:8100/api/v1/networks/templates/export/1 \
-o my-network.json

Via CLI​

chainlaunch network export --id 1 --output my-network.json

Template Structure​

{
"version": "2.0.0",
"platform": "FABRIC",
"name": "supply-chain-network",
"description": "3-org supply chain network",
"variables": [
{
"name": "org1",
"type": "organization",
"description": "Manufacturing org"
},
{
"name": "org1Peer",
"type": "node",
"description": "Org1 peer node"
},
{
"name": "org1Key",
"type": "key",
"description": "Org1 signing key"
}
],
"network": {
"organizations": [
{
"mspId": "${org1.mspId}",
"peers": ["${org1Peer.id}"],
"orderers": ["${orderer1.id}"]
}
],
"channels": [
{
"name": "supply-chain",
"organizations": ["${org1.mspId}", "${org2.mspId}"],
"policies": {
"Readers": { "type": "ImplicitMeta", "rule": "ANY Readers" },
"Writers": { "type": "ImplicitMeta", "rule": "ANY Writers" },
"Admins": { "type": "ImplicitMeta", "rule": "MAJORITY Admins" }
}
}
],
"chaincodes": [
{
"name": "asset-tracker",
"version": "1.0",
"language": "golang",
"dockerImage": "chaincode/asset-tracker:1.0"
}
]
}
}

Validate a Template​

Before importing, validate that a template is well-formed and all variables can be resolved:

curl -X POST http://localhost:8100/api/v1/networks/templates/validate \
-H "Content-Type: application/json" \
-d @my-network.json

Response:

{
"valid": true,
"variables": [
{ "name": "org1", "type": "organization", "resolved": false },
{ "name": "org1Peer", "type": "node", "resolved": false }
],
"warnings": []
}

If valid is false, the response includes errors explaining what's wrong.

Import a Template​

Import creates the network and all associated resources (chaincodes, channels) in one operation.

Via API​

curl -X POST http://localhost:8100/api/v1/networks/templates/import \
-H "Content-Type: application/json" \
-d '{
"template": <template-json>,
"variableBindings": {
"org1": { "organizationId": 1 },
"org1Peer": { "nodeId": 5 },
"org1Key": { "keyId": 3 },
"org2": { "organizationId": 2 },
"orderer1": { "nodeId": 10 }
}
}'

The variableBindings map template variables to actual resources on the target instance. You need to create the organizations, nodes, and keys first, then bind them during import.

Variable Types​

TypePlaceholderResolves to
organization${varName.mspId}Organization MSP ID
node${varName.id}Node ID
key${varName.id}Key ID
mspId${varName}Direct MSP ID string
ethereumAddress${varName}Ethereum address (Besu)
publicKey${varName}Public key hex (Besu)

Besu Templates​

Besu templates include genesis configuration with validator key references:

{
"version": "2.0.0",
"platform": "BESU",
"name": "defi-network",
"variables": [
{ "name": "validator0Key", "type": "key" },
{ "name": "validator1Key", "type": "key" }
],
"network": {
"chainId": 1337,
"consensus": "QBFT",
"blockPeriod": 5,
"epochLength": 30000,
"validatorKeys": [
"${validator0Key.id}",
"${validator1Key.id}"
],
"alloc": {
"${validator0Key.ethereumAddress}": {
"balance": "1000000000000000000000"
}
},
"smartContracts": [
{
"name": "TokenContract",
"abi": "[{...}]",
"bytecode": "0x608060..."
}
]
}
}

Example Templates​

ChainLaunch ships with example templates in the examples/templates/ directory:

TemplatePlatformDescription
fabric-supply-chainFabric3-org supply chain with asset tracking chaincode
besu-defi-networkBesu4-validator QBFT network with token contract
fabric-multi-orgFabricMulti-org consortium with custom policies

Use Cases​

  • Repeatable deployments — export a staging network template, import in production
  • Client projects — system integrators can create template libraries for common patterns
  • Disaster recovery — templates + backups give you full recovery capability
  • Training — distribute pre-built network templates for workshops
  • Cross-instance sharing — combined with Node Sharing, templates enable multi-org consortiums

Next Steps​