Symbion Documentation
Complete technical reference for the Symbion Web4 AI Agents platform on BNB Smart Chain (BSC Mainnet, Chain ID 56).
Quick Start
Mint your first Symbion AI Agent via the frontend or directly via web3:
import { ethers } from 'ethers';
const CONTRACT = '';
const ABI = [/* see Full ABI section below */];
// Connect wallet (MetaMask / any EIP-1193 provider)
const provider = new ethers.providers.Web3Provider(window.ethereum);
await provider.send('eth_requestAccounts', []);
const signer = provider.getSigner();
const contract = new ethers.Contract(CONTRACT, ABI, signer);
// Upload metadata to IPFS first, then mint
const metadataURI = 'ipfs://QmYour...MetadataHash';
const tx = await contract.mintAgent(metadataURI, {
value: ethers.utils.parseEther('0.01'), // 0.01 BNB mint fee
});
const receipt = await tx.wait();
console.log('Agent minted! TX:', tx.hash);
// tokenId is emitted in the AgentMinted eventipfs://Qm… URI as the argument.
Contract Methods
Write Functions
| Function | Description | Value |
|---|---|---|
| mintAgent(string tokenURI_) | Mint a new AI Agent NFT. Returns the new tokenId via AgentMinted event. | 0.01 BNB |
| toggleAgent(uint256 tokenId) | Activate or pause an agent. Only callable by the token owner. Emits AgentToggled. | — |
| listAgent(uint256 tokenId, uint256 price) | List an agent on the marketplace at the given price (in wei). Token must not already be listed. | — |
| unlistAgent(uint256 tokenId) | Remove a listing. Only callable by the original lister. | — |
| buyAgent(uint256 tokenId) | Purchase a listed agent. Send exact listing price as msg.value. BNB transferred to seller. | listing price |
| safeTransferFrom(from, to, tokenId) | Standard ERC-721 transfer. Transfers ownership of an agent. | — |
Read Functions
| Function | Returns |
|---|---|
| balanceOf(address owner) | Number of agents owned by address (uint256) |
| ownerOf(uint256 tokenId) | Owner address of token (address) |
| tokenURI(uint256 tokenId) | IPFS metadata URI for the token (string) |
| totalSupply() | Total minted agents (uint256) |
| tokenOfOwnerByIndex(address, uint256) | Token ID at given index for owner (uint256) |
| getAgentStatus(uint256 tokenId) | true if agent is active (bool) |
| getListedAgents() | Array of all active listings: (tokenId, seller, price, tokenURI) |
| mintPrice() | Current mint price in wei (uint256) |
Metadata Schema
Upload a JSON file matching this schema to IPFS before minting. The URI is stored immutably on-chain.
{
"name": "QuantumYield-Alpha",
"description": "Symbion AI Agent: Maximize yield via PancakeSwap auto-compound",
"image": "ipfs://QmYourImageHash", // IPFS image URI
"attributes": [
{ "trait_type": "Risk Level", "value": 5 },
{ "trait_type": "Protocols", "value": "PancakeSwap, Venus" },
{ "trait_type": "Status", "value": "Active" },
{ "trait_type": "Platform", "value": "Symbion Web4" }
],
"aiPrompt": "Maximize yield by auto-compounding on PancakeSwap...",
"riskLevel": 5, // 1-10
"targetProtocols": ["PancakeSwap", "Venus"],
"agentColor": "#00F0FF", // hex color for UI
"createdAt": 1720000000000 // Unix ms
}Integration Guide
Read and write Symbion agent data from your own dApp:
// Read agents owned by a wallet
const balance = await contract.balanceOf(userAddress);
const tokenIds = await Promise.all(
Array.from({ length: Number(balance) }, (_, i) =>
contract.tokenOfOwnerByIndex(userAddress, i)
)
);
// Fetch metadata for each token
const agents = await Promise.all(tokenIds.map(async tokenId => {
const uri = await contract.tokenURI(tokenId);
const isActive = await contract.getAgentStatus(tokenId);
const meta = await fetch(ipfsToHttp(uri)).then(r => r.json());
return { tokenId, uri, isActive, meta };
}));
// Toggle agent activation
const tx = await contract.toggleAgent(tokenId);
await tx.wait(); // wait for BSC confirmation
// List agent on marketplace
const priceWei = ethers.utils.parseEther('0.5');
const tx2 = await contract.listAgent(tokenId, priceWei);
await tx2.wait();// Get all listings
const listings = await contract.getListedAgents();
// listings = [{ tokenId, seller, price, tokenURI }, ...]
// Buy a specific listing
const listing = listings[0];
const tx = await contract.buyAgent(listing.tokenId, {
value: listing.price, // exact BNB amount required
});
await tx.wait();
console.log('Purchase complete!', tx.hash);Protocol Integration
Extend Symbion by integrating your own DeFi protocol with the AI Agent execution engine:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
/// @title ISymbionProtocol
/// @notice Implement this interface to integrate a DeFi protocol with Symbion AI Agents
interface ISymbionProtocol {
/// @notice Called when an AI Agent executes a strategy step
/// @param agentId The NFT tokenId of the executing agent
/// @param params ABI-encoded strategy parameters (protocol-specific)
/// @return success Whether the execution succeeded
/// @return yield Amount of yield generated (in protocol base token wei)
function executeStrategy(
uint256 agentId,
bytes calldata params
) external returns (bool success, uint256 yield);
/// @notice Returns current protocol health metrics
/// @return tvl Total value locked in wei
/// @return apr Annual percentage rate (basis points, 100 = 1%)
/// @return isActive Whether the protocol is currently operational
function getProtocolMetrics() external view returns (
uint256 tvl,
uint256 apr,
bool isActive
);
/// @notice Human-readable protocol name
function protocolName() external view returns (string memory);
}
/// @title Example: Integrating a custom DEX
contract MyDEXIntegration is ISymbionProtocol {
address public immutable router;
string public override protocolName = "MyDEX";
constructor(address _router) { router = _router; }
function executeStrategy(uint256 agentId, bytes calldata params)
external override returns (bool, uint256)
{
(address tokenIn, address tokenOut, uint256 amount) =
abi.decode(params, (address, address, uint256));
// Execute swap on your DEX...
return (true, 0);
}
function getProtocolMetrics() external view override returns (uint256, uint256, bool) {
return (1_000_000 ether, 1500, true); // $1M TVL, 15% APR
}
}Full ABI
Copy the complete contract ABI for use in your dApp:
Contract Source
Full Solidity source. Deploy using Hardhat or Remix on BSC Mainnet:
🚀 合约部署完整教程
零基础也能完成!按照下面的步骤把 Symbion 智能合约部署到 BSC 主网,全程约 15 分钟。
- ✅ 电脑已安装 Node.js 18+(nodejs.org 下载 LTS 版本)
- ✅ 已安装 MetaMask 浏览器插件,且有一个钱包地址
- ✅ 该钱包地址里有至少 0.05 BNB(用于支付 gas,部署约消耗 0.01~0.03 BNB)
- ✅ 注册了 BscScan 账号(免费,用于验证合约源码)
导出私钥步骤:
- 打开 MetaMask → 点击右上角三个点 → 账户详情
- 点击 导出私钥 → 输入 MetaMask 密码确认
- 复制显示的 64 位十六进制字符串(形如
abc123...def456) - 妥善保存,稍后会用到
- 登录 bscscan.com
- 点击右上角用户名 → My Profile → API Keys
- 点击 Add,随意填写名称(如 "symbion"),点击 Create
- 复制生成的 API Key(形如
ABC123XYZ...)
打开终端(Windows 用 PowerShell 或 CMD),依次运行:
# 创建新文件夹并进入 mkdir symbion-deploy cd symbion-deploy # 初始化 npm 项目(一路回车) npm init -y # 安装必要依赖(约 2-3 分钟) npm install --save-dev hardhat @nomicfoundation/hardhat-toolbox npm install @openzeppelin/contracts dotenv
然后初始化 Hardhat:
npx hardhat init # 出现提示时选择: # ❯ Create a JavaScript project ← 选这个,回车 # Hardhat project root: ... ← 直接回车 # Do you want to add .gitignore? ← 输入 y,回车 # Do you want to install ...? ← 输入 y,回车
4a. 创建合约文件 — 在项目根目录下的 contracts/ 文件夹里,删除默认的 Lock.sol,新建 SymbionAgent.sol,将上方"Contract Source"章节的完整 Solidity 代码粘贴进去保存。
4b. 创建 .env 文件 — 在项目根目录新建 .env 文件(注意没有文件名,只有扩展名):
PRIVATE_KEY=你的MetaMask私钥(去掉开头的0x,只要64位十六进制) BSCSCAN_API_KEY=你的BscScan_API_Key
.gitignore 里有 .env 这一行!绝对不要上传私钥。4c. 替换 hardhat.config.js — 用以下内容完整替换项目根目录的 hardhat.config.js:
require("@nomicfoundation/hardhat-toolbox");
require("dotenv").config();
module.exports = {
solidity: {
version: "0.8.20",
settings: { optimizer: { enabled: true, runs: 200 } }
},
networks: {
bsc: {
url: "https://bsc-dataseed1.binance.org",
accounts: [`0x${process.env.PRIVATE_KEY}`],
chainId: 56,
gasPrice: 3000000000, // 3 Gwei(BSC 标准)
},
bscTestnet: { // 测试网(可选)
url: "https://data-seed-prebsc-1-s1.binance.org:8545",
accounts: [`0x${process.env.PRIVATE_KEY}`],
chainId: 97,
}
},
etherscan: {
apiKey: {
bsc: process.env.BSCSCAN_API_KEY,
bscTestnet: process.env.BSCSCAN_API_KEY,
}
}
};4d. 创建部署脚本 — 在 scripts/ 文件夹里,删除默认的 deploy.js,新建内容如下:
const { ethers } = require("hardhat");
async function main() {
const [deployer] = await ethers.getSigners();
console.log("部署账户:", deployer.address);
const balance = await deployer.getBalance();
console.log("账户余额:", ethers.utils.formatEther(balance), "BNB");
if (balance.lt(ethers.utils.parseEther("0.05"))) {
throw new Error("❌ BNB 余额不足!请确保至少有 0.05 BNB 用于 gas");
}
console.log("\n🚀 开始部署 SymbionAgent...");
const SymbionAgent = await ethers.getContractFactory("SymbionAgent");
const agent = await SymbionAgent.deploy();
await agent.deployed();
console.log("\n✅ 部署成功!");
console.log("合约地址:", agent.address);
console.log("BscScan:", `https://bscscan.com/address/${agent.address}`);
console.log("\n📝 下一步:");
console.log(` 在 public/app.js 第6行,把 CONTRACT 改为: '${agent.address}'`);
}
main().catch((error) => {
console.error("❌ 部署失败:", error.message);
process.exit(1);
});# 先编译检查有无错误 npx hardhat compile # 看到 "Compiled X Solidity files successfully" 表示成功 # 【可选但推荐】先在测试网测试 npx hardhat run scripts/deploy.js --network bscTestnet # 测试网 BNB 从水龙头领取:https://testnet.binance.org/faucet-smart # 正式部署到 BSC 主网 npx hardhat run scripts/deploy.js --network bsc
部署成功后终端会显示:
✅ 部署成功! 合约地址: 0xAbCd1234...5678EfGh BscScan: https://bscscan.com/address/0xAbCd1234... 📝 下一步: 在 public/app.js 第6行,把 CONTRACT 改为: '0xAbCd1234...'
npx hardhat verify --network bsc 0xYOUR_CONTRACT_ADDRESS
看到 Successfully verified contract 表示成功。
现在打开 bscscan.com 搜索你的合约地址,应该能看到绿色的 ✅ Verified 标记。
打开 public/app.js,找到文件顶部的 CFG 对象,修改第一行:
const CFG = {
// 把下面这行的地址替换为你刚才部署得到的合约地址 ↓
CONTRACT: '0xYOUR_DEPLOYED_CONTRACT_ADDRESS',
CHAIN_ID: 56,
// ... 其余不变
};保存后,重新推送到 GitHub(或重新上传到 Vercel),Vercel 会自动重新部署:
git add public/app.js git commit -m "feat: set deployed contract address" git push # Vercel 检测到推送后自动重新部署,约 30 秒完成
- 用户现在可以访问你的 Vercel 网址,连接 MetaMask,真实 Mint Agent NFT
- 所有交易都在 BSC 主网链上发生,可在 BscScan 查询
- 合约地址已自动显示在首页、Footer 和 Docs 页面
- ✅
.env文件不在 GitHub 上(检查 .gitignore) - ✅ 正式上线前在 BSC 测试网完整测试过所有功能
- ✅ 合约在 BscScan 上显示 Verified(绿色勾)
- ✅ 大额资金上线前建议委托 CertiK 等机构做安全审计
- ✅ 记下合约 owner 地址,它才能调用
withdraw()取出收益