Learn, Build, Deploy โ AI-powered smart contracts in minutes. No Solidity. No oracles. Just Python + AI.
All the tools and resources to begin building on GenLayer in one place.
Browser-based IDE. Write, deploy, and test your Intelligent Contracts without installing anything.
Open Studio โGet free GEN tokens for the Asimov testnet. Paste your wallet address and tokens arrive in seconds.
Get Tokens โFull API reference, guides, and deep dives into GenLayer's architecture and SDK.
Read Docs โPre-configured starter with Vite + genlayer-js. Fork it and you're already halfway done.
Fork on GitHub โBefore writing code, understand the two breakthroughs that make GenLayer unique.
When your contract calls an AI model, a randomly-selected group of validators each run the contract independently โ each with their own AI (GPT, LLaMA, Mistralโฆ).
One validator is the Leader: they run first and propose a result. Other validators verify it. If the majority agree, the result is accepted on-chain.
Five validators might get five differently-worded LLM responses. "Yes", "Definitely!", "Affirmative" โ all mean the same thing but aren't identical strings.
The Equivalence Principle defines what counts as agreement. You choose the rule in your contract.
| Mode | When to Use | Example |
|---|---|---|
| strict_eq | Byte-for-byte identical results required | Boolean True/False, exact numbers |
| non_comparative | Each validator checks their own result against a rule | "Does the response contain 'YES'?" |
| comparative | Second LLM call checks if two results mean the same thing | Long-form text, subjective answers |
No terminal. No installs. Just your browser and 5 steps.
Navigate to studio.genlayer.com. This is your full development environment โ a browser-based IDE that runs a GenLayer node in the cloud. No Docker, no npm, no configuration files.
In the left sidebar, click the "+" button next to "Contracts". Name your file YesNoOracle.py. The Studio will open a blank Python editor for you.
Copy the complete contract from Section 4 below and paste it into the editor. Studio will syntax-highlight it immediately.
In the right panel, click "Deploy Contract". Since our __init__ takes no arguments, just confirm. Watch the transaction status change: PENDING โ ACCEPTED โ FINALIZED.
0x1a2b3cโฆ). Copy it โ you'll need it for the frontend.
In the "Execute Transaction" panel, select ask_question, type "Is water wet?" as the argument, and click "Send Transaction". Once finalized, call get_latest() as a view method to see the stored YES/NO result.
A complete Python Intelligent Contract. Copy it, deploy it, and it works.
# { "Depends": "py-genlayer:test" }
# This header tells GenVM which SDK version to load.
from genlayer import *
class YesNoOracle(gl.Contract):
โโโ
AI Yes/No Oracle โ Intelligent Contract
Users ask any question. AI answers YES or NO.
All answers are stored permanently on-chain.
โโโ
```
# โโ State Variables (stored permanently on blockchain) โโโโโโโโโโโ
questions: gl.DynArray[str] # Every question asked
answers: gl.DynArray[bool] # YES=True / NO=False
question_count: int # Total questions answered
# โโ Constructor (called once at deployment) โโโโโโโโโโโโโโโโโโโโโโ
def __init__(self):
self.questions = gl.DynArray[str]()
self.answers = gl.DynArray[bool]()
self.question_count = 0
# โโ Write Method: ask a question โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
@gl.public.write
def ask_question(self, question: str) -> None:
"""Send a question. AI decides YES or NO. Stored on-chain."""
# This inner function runs in GenLayer's AI sandbox.
# Each validator executes it independently with their own LLM.
def call_ai():
prompt = f"""You are a concise Yes/No oracle.
```
The user asks: โ{question}โ
Rules:
- Answer ONLY with โYESโ or โNOโ โ nothing else.
- Base your answer on general knowledge and common sense.
โโโ
raw = gl.exec_prompt(prompt)
# Parse to boolean so strict_eq works perfectly
return โYESโ in raw.strip().upper()
```
# Equivalence Principle: all validators must return same boolean
ai_answer: bool = gl.eq_principle_strict_eq(call_ai)
# Store result permanently on-chain
self.questions.append(question)
self.answers.append(ai_answer)
self.question_count += 1
```
# โโ View Methods (read-only, free, no transaction needed) โโโโโโโโ
@gl.public.view
def get_answer(self, index: int) -> dict:
if index >= self.question_count:
raise Exception(โIndex out of rangeโ)
return {
โquestionโ: self.questions[index],
โanswerโ: โYESโ if self.answers[index] else โNOโ,
โindexโ: index,
}
@gl.public.view
def get_latest(self) -> dict:
if self.question_count == 0:
return {โquestionโ: โNone yetโ, โanswerโ: โN/Aโ, โindexโ: -1}
return self.get_answer(self.question_count - 1)
@gl.public.view
def get_all_answers(self) -> list:
return [self.get_answer(i) for i in range(self.question_count)]
@gl.public.view
def get_count(self) -> int:
return self.question_count
Sends your prompt to the validator's configured LLM. Each validator uses their own AI model โ GenLayer routes it automatically.
Wraps your AI function. Runs it in the non-deterministic sandbox and requires all validators to return the exact same boolean.
A dynamic array that GenLayer serializes and stores on-chain. Survives between calls forever, unlike a regular Python list.
.write changes state and requires a transaction. .view is read-only and free โ no gas, no signing.
This is how your website talks to the blockchain. Three core functions you'll use in every GenLayer dApp.
npm install genlayer-js โ or fork the official boilerplate which has it pre-configured.
// Sends a write transaction
const txHash = await client.writeContract({
address: CONTRACT_ADDRESS,
functionName: 'ask_question',
args: [question],
value: 0n,
});
// Wait for AI validators to agree
await client.waitForTransactionReceipt({
hash: txHash,
status: TransactionStatus.FINALIZED,
retries: 100,
interval: 3000,
});
// Free read โ no transaction needed
const result = await client.readContract({
address: CONTRACT_ADDRESS,
functionName: โget_latestโ,
args: [],
stateStatus: โacceptedโ,
});
// Returns:
// { question: โIs water wet?โ,
// answer: โYESโ, index: 0 }
import { createClient, createAccount } from 'genlayer-js';
import { simulator } from 'genlayer-js/chains';
import { TransactionStatus } from 'genlayer-js/types';
// โโ Config โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
const CONTRACT_ADDRESS = โ0xYOUR_CONTRACT_ADDRESS_HEREโ;
// โโ Create client connected to Studio simulator โโโโโโโโโโ
const account = createAccount();
const client = createClient({ chain: simulator, account });
// โโ Ask a question โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
async function askQuestion(question) {
await client.initializeConsensusSmartContract();
const txHash = await client.writeContract({
address: CONTRACT_ADDRESS, functionName: โask_questionโ,
args: [question], value: 0n,
});
return client.waitForTransactionReceipt({
hash: txHash, status: TransactionStatus.FINALIZED,
retries: 100, interval: 3000,
});
}
// โโ Read the latest answer โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
async function getLatest() {
return client.readContract({
address: CONTRACT_ADDRESS, functionName: โget_latestโ,
args: [], stateStatus: โacceptedโ,
});
}
// โโ Read all answers โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
async function getAllAnswers() {
return client.readContract({
address: CONTRACT_ADDRESS, functionName: โget_all_answersโ,
args: [], stateStatus: โacceptedโ,
});
}
Trace a single question โ "Is coffee healthy?" โ all the way through the system.
writeContract transaction to the network.
strict_eq.
readContract (free) to display the result.
This is a real dApp โ not a mock. Questions go to a deployed YesNoOracle Intelligent Contract. AI validators reach consensus. Results live on the blockchain.
CONTRACT_ADDRESS near the bottom, and paste your deployed contract address from GenLayer Studio. Then this demo goes live.
writeContract() via genlayer-js. Multiple AI validators independently run gl.exec_prompt() with your question, then gl.eq_principle_strict_eq() ensures they agree on the same boolean before committing to chain state.
You've got the foundation. Here's the road ahead.
Complete this tutorial. Deploy YesNoOracle. Understand Optimistic Democracy.
Write contracts with web fetching. Use comparative equivalence. Add complex state.
Deploy to Asimov Testnet. Connect MetaMask. Use the faucet for real testnet tokens.
Build a full React app with genlayer-js. Handle wallet connections. Display live state.
Create something original. Submit to the Builder Portal. Join the GenLayer ecosystem.
You understand Optimistic Democracy, the Equivalence Principle, and you've deployed a real AI-powered smart contract. The rest is up to you.