Files
hanzo.ai/app/(marketing)/blockchain/bundler/page.tsx
zeekay 11265a21fd Highlight every code sample with shiki in the code theme
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.
2026-10-05 01:31:58 -07:00

328 lines
8.8 KiB
TypeScript

import { sample } from '@/components/blockchain/sample'
import HanzoBundler from './view'
const EXAMPLES = [
{
language: "Solidity",
filename: "UserOpBuilder.sol",
code: `// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import "@account-abstraction/contracts/interfaces/IEntryPoint.sol";
import "@account-abstraction/contracts/interfaces/UserOperation.sol";
contract UserOpHelper {
IEntryPoint public immutable entryPoint;
constructor(address _entryPoint) {
entryPoint = IEntryPoint(_entryPoint);
}
// Encode a simple ETH transfer for UserOp callData
function encodeTransfer(address to, uint256 value) external pure returns (bytes memory) {
return abi.encodeWithSignature("execute(address,uint256,bytes)", to, value, "");
}
// Encode ERC20 transfer for UserOp callData
function encodeERC20Transfer(
address token,
address to,
uint256 amount
) external pure returns (bytes memory) {
bytes memory tokenCall = abi.encodeWithSignature("transfer(address,uint256)", to, amount);
return abi.encodeWithSignature("execute(address,uint256,bytes)", token, 0, tokenCall);
}
// Encode batch execution for UserOp callData
function encodeBatch(
address[] calldata targets,
uint256[] calldata values,
bytes[] calldata datas
) external pure returns (bytes memory) {
return abi.encodeWithSignature(
"executeBatch(address[],uint256[],bytes[])",
targets, values, datas
);
}
// Get gas limits for simulation
function estimateGas(UserOperation calldata userOp) external returns (
uint256 preVerificationGas,
uint256 verificationGasLimit,
uint256 callGasLimit
) {
// Simulate execution to estimate gas
try entryPoint.simulateValidation(userOp) {}
catch (bytes memory result) {
// Parse simulation result for gas estimates
}
}
// Get current nonce for account
function getNonce(address account) external view returns (uint256) {
return entryPoint.getNonce(account, 0);
}
}`,
},
{
language: "Node",
filename: "bundler.ts",
code: `import { HanzoBundler } from "@hanzo/blockchain";
const bundler = new HanzoBundler({
apiKey: process.env.HANZO_API_KEY,
});
// Submit a UserOperation
const result = await bundler.sendUserOperation({
chain: "ethereum",
userOp: {
sender: "0x...",
nonce: "0x0",
initCode: "0x",
callData: "0x...",
callGasLimit: "0x...",
verificationGasLimit: "0x...",
preVerificationGas: "0x...",
maxFeePerGas: "0x...",
maxPriorityFeePerGas: "0x...",
paymasterAndData: "0x",
signature: "0x...",
},
entryPoint: "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789",
});
// Track operation status
const status = await bundler.getUserOperationReceipt({
chain: "ethereum",
userOpHash: result.userOpHash,
});`,
},
{
language: "Python",
filename: "bundler.py",
code: `from hanzo_blockchain import HanzoBundler
bundler = HanzoBundler(api_key=os.environ["HANZO_API_KEY"])
# Submit a UserOperation
result = bundler.send_user_operation(
chain="ethereum",
user_op={
"sender": "0x...",
"nonce": "0x0",
"initCode": "0x",
"callData": "0x...",
"callGasLimit": "0x...",
"verificationGasLimit": "0x...",
"preVerificationGas": "0x...",
"maxFeePerGas": "0x...",
"maxPriorityFeePerGas": "0x...",
"paymasterAndData": "0x",
"signature": "0x...",
},
entry_point="0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789",
)
# Track operation status
status = bundler.get_user_operation_receipt(
chain="ethereum",
user_op_hash=result.user_op_hash,
)`,
},
{
language: "Go",
filename: "bundler.go",
code: `package main
import (
"os"
hanzo "github.com/hanzoai/blockchain-go"
)
func main() {
bundler := hanzo.NewBundler(os.Getenv("HANZO_API_KEY"))
// Submit a UserOperation
result, err := bundler.SendUserOperation(&hanzo.SendUserOpRequest{
Chain: "ethereum",
UserOp: &hanzo.UserOperation{
Sender: "0x...",
Nonce: "0x0",
InitCode: "0x",
CallData: "0x...",
CallGasLimit: "0x...",
VerificationGasLimit: "0x...",
PreVerificationGas: "0x...",
MaxFeePerGas: "0x...",
MaxPriorityFeePerGas: "0x...",
PaymasterAndData: "0x",
Signature: "0x...",
},
EntryPoint: "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789",
})
// Track operation status
status, err := bundler.GetUserOperationReceipt(&hanzo.ReceiptRequest{
Chain: "ethereum",
UserOpHash: result.UserOpHash,
})
}`,
},
{
language: "Rust",
filename: "bundler.rs",
code: `use hanzo_blockchain::{Bundler, UserOperation};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let bundler = Bundler::new(std::env::var("HANZO_API_KEY")?);
// Submit a UserOperation
let result = bundler.send_user_operation(
"ethereum",
UserOperation {
sender: "0x...".into(),
nonce: "0x0".into(),
init_code: "0x".into(),
call_data: "0x...".into(),
call_gas_limit: "0x...".into(),
verification_gas_limit: "0x...".into(),
pre_verification_gas: "0x...".into(),
max_fee_per_gas: "0x...".into(),
max_priority_fee_per_gas: "0x...".into(),
paymaster_and_data: "0x".into(),
signature: "0x...".into(),
},
"0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789",
).await?;
// Track operation status
let status = bundler.get_user_operation_receipt(
"ethereum",
&result.user_op_hash,
).await?;
Ok(())
}`,
},
{
language: "C",
filename: "bundler.c",
code: `#include <hanzo/blockchain.h>
#include <stdlib.h>
int main(void) {
hanzo_bundler_t *bundler = hanzo_bundler_new(getenv("HANZO_API_KEY"));
// Build UserOperation
hanzo_user_op_t user_op = {
.sender = "0x...",
.nonce = "0x0",
.init_code = "0x",
.call_data = "0x...",
.call_gas_limit = "0x...",
.verification_gas_limit = "0x...",
.pre_verification_gas = "0x...",
.max_fee_per_gas = "0x...",
.max_priority_fee_per_gas = "0x...",
.paymaster_and_data = "0x",
.signature = "0x...",
};
// Submit UserOperation
hanzo_result_t *result = hanzo_bundler_send_user_op(
bundler, "ethereum", &user_op,
"0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789"
);
// Track operation status
hanzo_receipt_t *status = hanzo_bundler_get_receipt(
bundler, "ethereum", result->user_op_hash
);
hanzo_receipt_free(status);
hanzo_result_free(result);
hanzo_bundler_free(bundler);
return 0;
}`,
},
{
language: "C++",
filename: "bundler.cpp",
code: `#include <hanzo/blockchain.hpp>
#include <cstdlib>
int main() {
auto bundler = hanzo::Bundler(std::getenv("HANZO_API_KEY"));
// Build UserOperation
hanzo::UserOperation user_op{
.sender = "0x...",
.nonce = "0x0",
.init_code = "0x",
.call_data = "0x...",
.call_gas_limit = "0x...",
.verification_gas_limit = "0x...",
.pre_verification_gas = "0x...",
.max_fee_per_gas = "0x...",
.max_priority_fee_per_gas = "0x...",
.paymaster_and_data = "0x",
.signature = "0x...",
};
// Submit UserOperation
auto result = bundler.send_user_operation(
"ethereum",
user_op,
"0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789"
);
// Track operation status
auto status = bundler.get_user_operation_receipt(
"ethereum",
result.user_op_hash
);
return 0;
}`,
},
{
language: "Ruby",
filename: "bundler.rb",
code: `require 'hanzo/blockchain'
bundler = Hanzo::Bundler.new(api_key: ENV['HANZO_API_KEY'])
# Submit a UserOperation
result = bundler.send_user_operation(
chain: 'ethereum',
user_op: {
sender: '0x...',
nonce: '0x0',
init_code: '0x',
call_data: '0x...',
call_gas_limit: '0x...',
verification_gas_limit: '0x...',
pre_verification_gas: '0x...',
max_fee_per_gas: '0x...',
max_priority_fee_per_gas: '0x...',
paymaster_and_data: '0x',
signature: '0x...',
},
entry_point: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789'
)
# Track operation status
status = bundler.get_user_operation_receipt(
chain: 'ethereum',
user_op_hash: result.user_op_hash
)`,
},
]
/** The page, with every language's sample highlighted where it is built (components/code). */
export default function Page() {
return <HanzoBundler codeExamples={EXAMPLES.map(sample)} />
}