Web3 API Reference
Web3 API Reference
Complete API reference for Web3 integration with Macro.
Standard Ethereum Provider API
Macro implements EIP-1193. All standard Ethereum provider methods supported.
eth_requestAccounts
Request user's wallet address.
const accounts = await ethereum.request({
method: 'eth_requestAccounts'
});
// Returns: ['0x...']eth_accounts
Get currently connected accounts.
const accounts = await ethereum.request({
method: 'eth_accounts'
});eth_sendTransaction
Send a transaction.
const txHash = await ethereum.request({
method: 'eth_sendTransaction',
params: [{
from: '0x...',
to: '0x...',
value: '0x...',
data: '0x...',
gas: '0x...',
gasPrice: '0x...'
}]
});Macro intercepts: Signing Sandbox analyzes before user approval.
personal_sign
Sign a message.
const signature = await ethereum.request({
method: 'personal_sign',
params: [message, address]
});eth_signTypedData_v4
Sign typed structured data (EIP-712).
const signature = await ethereum.request({
method: 'eth_signTypedData_v4',
params: [address, typedDataJSON]
});Macro enhancement: Displays structured data in human-readable table.
wallet_switchEthereumChain
Request network switch.
await ethereum.request({
method: 'wallet_switchEthereumChain',
params: [{ chainId: '0x1' }] // Mainnet
});wallet_addEthereumChain
Add custom network.
await ethereum.request({
method: 'wallet_addEthereumChain',
params: [{
chainId: '0x89',
chainName: 'Polygon Mainnet',
rpcUrls: ['https://polygon-rpc.com'],
nativeCurrency: {
name: 'MATIC',
symbol: 'MATIC',
decimals: 18
},
blockExplorerUrls: ['https://polygonscan.com']
}]
});Macro-Specific API
Privacy-enhanced methods:
macro_getPrivacyFeatures
Check available privacy features.
const features = await ethereum.request({
method: 'macro_getPrivacyFeatures'
});
// Returns:
// {
// mixer: true,
// privateSwaps: true,
// signingPolicy: true,
// vpn: true,
// privacyProfiles: true
// }macro_sendPrivateTransaction
Send transaction through privacy mixer.
const txHash = await ethereum.request({
method: 'macro_sendPrivateTransaction',
params: [{
from: '0x...',
to: '0x...',
value: '0x...',
privacy: 'mixer', // 'mixer' | 'flashbots' | 'direct'
mixerDelay: 3600 // seconds (optional)
}]
});
// Returns transaction hash after mixingParameters:
privacy: Routing method (mixer, flashbots, or direct)mixerDelay: Delay before withdrawal (seconds, optional)
macro_privateSwap
Execute MEV-protected swap.
const result = await ethereum.request({
method: 'macro_privateSwap',
params: [{
fromToken: '0x...', // Token address or 'ETH'
toToken: '0x...',
amount: '1000000000000000000', // Wei
slippage: 0.5, // Percent
recipient: '0x...' // Optional, defaults to sender
}]
});
// Returns:
// {
// txHash: '0x...',
// amountOut: '...',
// effectivePrice: '...'
// }macro_getSigningPolicy
Get current signing policy for connected dApp.
const policy = await ethereum.request({
method: 'macro_getSigningPolicy',
params: [dAppOrigin]
});
// Returns:
// {
// maxApproval: '1000000000000000000', // Wei
// allowedFunctions: ['swap', 'addLiquidity'],
// blockedFunctions: ['approve(address,uint256)'],
// requiresHardwareWallet: false
// }macro_getVPNStatus
Check VPN status.
const vpnStatus = await ethereum.request({
method: 'macro_getVPNStatus'
});
// Returns:
// {
// enabled: true,
// connected: true,
// exitRegion: 'US',
// latency: 45, // ms
// health: 'good' // 'good' | 'degraded' | 'poor'
// }macro_getCurrentProfile
Get active Privacy Profile info.
const profile = await ethereum.request({
method: 'macro_getCurrentProfile'
});
// Returns:
// {
// name: 'Degen',
// id: 'profile_abc123',
// color: '#9333EA'
// }Events
Listen for Macro-specific events:
profileChanged
Fires when user switches Privacy Profile.
ethereum.on('profileChanged', (profile) => {
console.log('New profile:', profile.name);
// Disconnect and require re-connection
});vpnStatusChanged
Fires when VPN status changes.
ethereum.on('vpnStatusChanged', (status) => {
console.log('VPN now:', status.enabled);
});signingPolicyUpdated
Fires when user updates signing policy for your dApp.
ethereum.on('signingPolicyUpdated', (policy) => {
console.log('New policy:', policy);
});Error Codes
Macro-specific error codes:
4001
User rejected request in signing sandbox
4100
Unauthorized (not connected)
4200
Request not supported
4900
Disconnected from network
5001
Policy violation (transaction blocked by signing policy)
5002
Privacy feature unavailable
5003
VPN required but not connected
Example handling:
try {
const tx = await ethereum.request({...});
} catch (error) {
if (error.code === 5001) {
alert('Transaction blocked by your signing policy');
} else if (error.code === 5002) {
alert('Privacy feature not available');
}
}Privacy API Reference
Last updated