A self-evolving intelligent contract on GenLayer. Each generation is a new contract deployed with LLM-mutated source code — not data-driven evolution, actual code evolution.
The contract stores its own source code as a string. When evolve() is called:
- The source code is passed to an LLM with instructions to mutate it
- Validators verify the mutation preserves the core structure (class name,
evolvemethod, storage fields) - The mutated code is deployed as a new child contract via
gl.deploy_contract() - The child is a new generation — same pattern, new behavior
Each generation keeps a registry of its children. Each child knows its parent and generation number. If a child is broken, the parent still works. Anyone can call evolve() on any generation to spawn the next one.
Generation 0 ──evolve()──► Generation 1 ──evolve()──► Generation 2
│ │
└──evolve()──► Generation 1b (branching is possible)
| Method | Type | Description |
|---|---|---|
evolve(suggestion="") |
write | Spawn a mutated child contract. Optional suggestion guides the mutation direction. |
get_code() |
view | Read the contract's current source code |
get_lineage() |
view | JSON with generation number, parent address, children addresses, and own address |
get_generation() |
view | Current generation number |
get_children() |
view | List of child contract addresses |
Generation 0: 0x1AD7273103F49098Be7475c54622ad787a5cC006
- GenLayer CLI installed
- Node.js
# Install dependencies
npm install
# Select the network (studionet, localnet, or a testnet)
genlayer network set studionet
# Deploy generation 0
npm run deployThe deploy script automatically passes the contract's own source code as a constructor argument, creating generation 0 with no parent.
contracts/living_organism.py # The living organism contract
deploy/deployScript.ts # Deployment script (reads contract, deploys gen 0)
- Factory pattern, not self-upgrade — each generation is a separate contract. No storage layout constraints. Broken children don't affect parents.
- Code as state — the contract stores its own source as a
strfield, readable viaget_code(). This same string gets passed to the LLM for mutation and togl.deploy_contract()for spawning. - Consensus — leader asks the LLM to mutate the code, validator checks structural compatibility (both must preserve
evolve(), class structure, storage fields). - Open evolution — anyone can trigger
evolve()and pay gas. No owner restriction.
- GenLayer — AI-native blockchain
- GenLayer JS SDK — deployment and interaction
MIT