mirror of
https://github.com/hanzo-apps/hanzo.ai.git
synced 2026-10-30 14:58:08 +00:00
Code on hanzo.ai was plain monospace: 285 blocks across 200 pages, one of them hand-inked in four greys. components/code now renders each sample at build with shiki and @hanzo/ui's codeTheme (Dracula dark, GitHub Light light), every colour written as light-dark() so the page's color-scheme picks it, on the theme's own ground. The page ships the coloured spans and no highlighter; e2e/gates/code.spec.ts holds both. A client page that shows code is split into a server page.tsx that owns the sample and a client view.tsx that takes the highlighted node: ProductLanding's code.source, the blockchain pages' codeExamples, the models kit Sample, the guest-key card, realtime, analytics, payments, sdks and the rest. Transcripts, agent prompts and ASCII diagrams are not code and keep their markup. Takes @hanzo/ui 8.27.83 for codeTheme and @hanzo/design 0.5.35 with it, regenerates app/gui.css for the new theme keys, and lowers the raw-colour allowance to 58: the samples' literal inks are gone.
313 lines
7.2 KiB
TypeScript
313 lines
7.2 KiB
TypeScript
import { sample } from '@/components/blockchain/sample'
|
|
import HanzoExplorer from './view'
|
|
|
|
const EXAMPLES = [
|
|
{
|
|
language: "Solidity",
|
|
filename: "VerifiedContract.sol",
|
|
code: `// SPDX-License-Identifier: MIT
|
|
pragma solidity ^0.8.24;
|
|
|
|
import "@hanzo/explorer/IHanzoExplorer.sol";
|
|
|
|
/// @title VerifiedContract - Contract verification and analytics integration
|
|
/// @notice Events and functions designed for explorer indexing and verification
|
|
contract VerifiedContract {
|
|
// Events optimized for explorer indexing
|
|
event ContractVerified(
|
|
address indexed contractAddress,
|
|
bytes32 indexed codeHash,
|
|
string sourceUrl,
|
|
uint256 timestamp
|
|
);
|
|
|
|
event TransactionDecoded(
|
|
bytes32 indexed txHash,
|
|
address indexed target,
|
|
bytes4 selector,
|
|
bytes decodedParams
|
|
);
|
|
|
|
event AddressLabeled(
|
|
address indexed account,
|
|
string label,
|
|
string category
|
|
);
|
|
|
|
// Verification status mapping
|
|
mapping(address => bool) public verified;
|
|
mapping(address => string) public sourceUrls;
|
|
|
|
// Mark a contract as verified with source code
|
|
function verifyContract(
|
|
address contractAddress,
|
|
string calldata sourceUrl
|
|
) external {
|
|
bytes32 codeHash = contractAddress.codehash;
|
|
verified[contractAddress] = true;
|
|
sourceUrls[contractAddress] = sourceUrl;
|
|
emit ContractVerified(contractAddress, codeHash, sourceUrl, block.timestamp);
|
|
}
|
|
|
|
// Log decoded transaction for explorer
|
|
function logDecodedTransaction(
|
|
bytes32 txHash,
|
|
address target,
|
|
bytes4 selector,
|
|
bytes calldata decodedParams
|
|
) external {
|
|
emit TransactionDecoded(txHash, target, selector, decodedParams);
|
|
}
|
|
|
|
// Label an address for easier identification
|
|
function labelAddress(
|
|
address account,
|
|
string calldata label,
|
|
string calldata category
|
|
) external {
|
|
emit AddressLabeled(account, label, category);
|
|
}
|
|
}`,
|
|
},
|
|
{
|
|
language: "Node",
|
|
filename: "explorer.ts",
|
|
code: `import { HanzoExplorer } from "@hanzo/blockchain";
|
|
|
|
const explorer = new HanzoExplorer({
|
|
apiKey: process.env.HANZO_API_KEY,
|
|
});
|
|
|
|
// Get transaction details
|
|
const tx = await explorer.getTransaction({
|
|
hash: "0x...",
|
|
chainId: 1,
|
|
});
|
|
|
|
console.log(tx.decoded); // Human-readable method call
|
|
console.log(tx.gasUsed);
|
|
console.log(tx.status);
|
|
|
|
// Get address history
|
|
const history = await explorer.getAddressHistory({
|
|
address: "0x...",
|
|
chainId: 1,
|
|
page: 1,
|
|
limit: 50,
|
|
});
|
|
|
|
// Search across chains
|
|
const results = await explorer.search({
|
|
query: "0x...", // Address, tx hash, or ENS
|
|
});`,
|
|
},
|
|
{
|
|
language: "Python",
|
|
filename: "explorer.py",
|
|
code: `from hanzo import HanzoExplorer
|
|
import os
|
|
|
|
explorer = HanzoExplorer(api_key=os.environ["HANZO_API_KEY"])
|
|
|
|
# Get transaction details
|
|
tx = await explorer.get_transaction(
|
|
hash="0x...",
|
|
chain_id=1
|
|
)
|
|
|
|
print(f"Method: {tx.decoded}")
|
|
print(f"Gas used: {tx.gas_used}")
|
|
print(f"Status: {tx.status}")
|
|
|
|
# Get address history
|
|
history = await explorer.get_address_history(
|
|
address="0x...",
|
|
chain_id=1,
|
|
page=1,
|
|
limit=50
|
|
)
|
|
|
|
# Search across chains
|
|
results = await explorer.search(query="0x...")
|
|
|
|
# Set up alerts
|
|
await explorer.create_alert(
|
|
address="0x...",
|
|
event="transfer",
|
|
threshold="1000000000000000000",
|
|
webhook="https://your-app.com/webhook"
|
|
)`,
|
|
},
|
|
{
|
|
language: "Go",
|
|
filename: "explorer.go",
|
|
code: `package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"github.com/hanzoai/hanzo-go/blockchain"
|
|
)
|
|
|
|
func main() {
|
|
explorer := blockchain.NewExplorer(os.Getenv("HANZO_API_KEY"))
|
|
|
|
// Get transaction details
|
|
tx, _ := explorer.GetTransaction(ctx, blockchain.TxQuery{
|
|
Hash: "0x...",
|
|
ChainID: 1,
|
|
})
|
|
|
|
fmt.Printf("Method: %s\\n", tx.Decoded)
|
|
fmt.Printf("Gas used: %d\\n", tx.GasUsed)
|
|
fmt.Printf("Status: %s\\n", tx.Status)
|
|
|
|
// Get address history
|
|
history, _ := explorer.GetAddressHistory(ctx, blockchain.HistoryQuery{
|
|
Address: "0x...",
|
|
ChainID: 1,
|
|
Page: 1,
|
|
Limit: 50,
|
|
})
|
|
|
|
// Search across chains
|
|
results, _ := explorer.Search(ctx, "0x...")
|
|
}`,
|
|
},
|
|
{
|
|
language: "Rust",
|
|
filename: "explorer.rs",
|
|
code: `use hanzo_blockchain::Explorer;
|
|
|
|
#[tokio::main]
|
|
async fn main() -> Result<()> {
|
|
let explorer = Explorer::new(std::env::var("HANZO_API_KEY")?);
|
|
|
|
// Get transaction details
|
|
let tx = explorer.get_transaction(TxQuery {
|
|
hash: "0x...".into(),
|
|
chain_id: 1,
|
|
}).await?;
|
|
|
|
println!("Method: {}", tx.decoded);
|
|
println!("Gas used: {}", tx.gas_used);
|
|
println!("Status: {}", tx.status);
|
|
|
|
// Get address history
|
|
let history = explorer.get_address_history(HistoryQuery {
|
|
address: "0x...".into(),
|
|
chain_id: 1,
|
|
page: 1,
|
|
limit: 50,
|
|
}).await?;
|
|
|
|
// Search across chains
|
|
let results = explorer.search("0x...").await?;
|
|
|
|
Ok(())
|
|
}`,
|
|
},
|
|
{
|
|
language: "C",
|
|
filename: "explorer.c",
|
|
code: `#include <hanzo/blockchain.h>
|
|
|
|
int main() {
|
|
hanzo_explorer_t *explorer = hanzo_explorer_new(getenv("HANZO_API_KEY"));
|
|
|
|
// Get transaction details
|
|
hanzo_tx_t tx;
|
|
hanzo_explorer_get_tx(explorer, "0x...", 1, &tx);
|
|
|
|
printf("Method: %s\\n", tx.decoded);
|
|
printf("Gas used: %llu\\n", tx.gas_used);
|
|
printf("Status: %s\\n", tx.status);
|
|
|
|
// Get address history
|
|
hanzo_history_t *history = hanzo_explorer_get_history(
|
|
explorer, "0x...", 1, 1, 50
|
|
);
|
|
|
|
// Search across chains
|
|
hanzo_search_result_t *results = hanzo_explorer_search(explorer, "0x...");
|
|
|
|
hanzo_explorer_free(explorer);
|
|
return 0;
|
|
}`,
|
|
},
|
|
{
|
|
language: "C++",
|
|
filename: "explorer.cpp",
|
|
code: `#include <hanzo/blockchain.hpp>
|
|
#include <iostream>
|
|
|
|
int main() {
|
|
auto explorer = hanzo::Explorer(std::getenv("HANZO_API_KEY"));
|
|
|
|
// Get transaction details
|
|
auto tx = explorer.getTransaction({
|
|
.hash = "0x...",
|
|
.chainId = 1
|
|
});
|
|
|
|
std::cout << "Method: " << tx.decoded << std::endl;
|
|
std::cout << "Gas used: " << tx.gasUsed << std::endl;
|
|
std::cout << "Status: " << tx.status << std::endl;
|
|
|
|
// Get address history
|
|
auto history = explorer.getAddressHistory({
|
|
.address = "0x...",
|
|
.chainId = 1,
|
|
.page = 1,
|
|
.limit = 50
|
|
});
|
|
|
|
// Search across chains
|
|
auto results = explorer.search("0x...");
|
|
|
|
return 0;
|
|
}`,
|
|
},
|
|
{
|
|
language: "Ruby",
|
|
filename: "explorer.rb",
|
|
code: `require 'hanzo/blockchain'
|
|
|
|
explorer = Hanzo::Explorer.new(api_key: ENV['HANZO_API_KEY'])
|
|
|
|
# Get transaction details
|
|
tx = explorer.get_transaction(
|
|
hash: '0x...',
|
|
chain_id: 1
|
|
)
|
|
|
|
puts "Method: #{tx.decoded}"
|
|
puts "Gas used: #{tx.gas_used}"
|
|
puts "Status: #{tx.status}"
|
|
|
|
# Get address history
|
|
history = explorer.get_address_history(
|
|
address: '0x...',
|
|
chain_id: 1,
|
|
page: 1,
|
|
limit: 50
|
|
)
|
|
|
|
# Search across chains
|
|
results = explorer.search(query: '0x...')
|
|
|
|
# Set up alerts
|
|
explorer.create_alert(
|
|
address: '0x...',
|
|
event: 'transfer',
|
|
threshold: '1000000000000000000',
|
|
webhook: 'https://your-app.com/webhook'
|
|
)`,
|
|
},
|
|
]
|
|
|
|
/** The page, with every language's sample highlighted where it is built (components/code). */
|
|
export default function Page() {
|
|
return <HanzoExplorer codeExamples={EXAMPLES.map(sample)} />
|
|
}
|