Darwin Quickstart

This guide provides a step-by-step guide for quickly interacting with the Darwin AI blockchain platform.
Prerequisites
Prepare Your EVM-Compatible Wallet: Ensure your wallet supports EVM standards and can interact with Ethereum-based smart contracts. We recommend using MetaMask.
Add Darwin Chain Network:
Visit the Darwin Chain website.
Scroll down -> click the Add Darwin Chain button.
Acquire $DNA Tokens:
Visit the Darwin Faucet at
https://darwin-faucet.example.com
You can participate in staking and transactions to obtain initial $DNA tokens.
Quickstart
Step 1: Create and Submit a Stake Transaction
Use the ether.js
to connect to the contract and call the stakeDNA
function:
import { ethers } from 'ethers';
// Connect to the provider (e.g., MetaMask)
const provider = new ethers.providers.Web3Provider(window.ethereum);
// Signer derived from the provider
const signer = provider.getSigner();
// Connect to the contract
const contract = new ethers.Contract('0x123...def', abi, signer);
const stakeAmount = ethers.utils.parseEther('100'); // Staking 100 $DNA
// Send the stake transaction
async function stakeDNA() {
const txResponse = await contract.stakeDNA(stakeAmount);
console.log('Transaction Response:', txResponse);
}
stakeDNA();
Step 2: Sign and Submit AI Transactions with EIP-712
This step details how to securely structure, sign, and submit an AI transaction using the EIP-712 standard with ethers.js
.
Define the domain and the types:
const domain = {
name: 'DarwinAI',
version: '1',
chainId: 1, // Specify the correct chain ID for your deployment
verifyingContract: '0x123...def' // Contract address that will verify the signature
};
const types = {
AIRequest: [
{ name: 'requestId', type: 'uint256' },
{ name: 'conversation', type: 'Prompt[]' }
],
Prompt: [
{ name: 'role', type: 'string' },
{ name: 'input', type: 'string' }
]
};
Define the conversation in a structured format, with each entry specifying the role and the corresponding input, encapsulating the interaction sequence:
const value = {
requestId: 1,
conversation: [
{ role: 'user', input: 'What are the benefits of blockchain?' },
{ role: 'system', input: 'Exploring decentralized solutions.' },
{ role: 'assistant', input: 'Blockchain provides security and transparency.' }
]
};
Sign the transaction:
async function signTransaction() {
const signer = provider.getSigner(); // Assumes provider is already set up
const signature = await signer._signTypedData(domain, types, value);
console.log('Signature:', signature);
return signature;
}
const signedData = await signTransaction();
Submit the signed transaction to the Relayer:
curl -X POST https://relayer.darwin.example.com/api/submit -H 'Content-Type: application/json' -d '{"signedData": "'"$signedData"'"}'
Step 3: Retrieve Streaming AI Results from the Query Mixer
Retrieve the AI-generated results from the Query Mixer using your unique requestId
:
curl -X GET "https://query-mixer.darwin.example.com/results?requestId=1" -H "Accept: text/event-stream"
When requesting streaming data, the server keeps the connection open, sending real-time updates as AI nodes process them. Each data packet contains a portion of the AI's response, allowing the client to process or display the information incrementally.
Last updated