Integration Guide

Integration Guide

Build dApps and services that integrate with Macro's privacy ecosystem.

Diagram 1

Getting Started

Macro supports standard Web3 APIs. Your existing dApp likely works out of the box.

Supported standards:

  • EIP-1193 (Ethereum Provider)

  • EIP-1102 (Account access)

  • EIP-712 (Typed data signing)

  • WalletConnect protocol

Provider Detection

Check for Macro:

if (window.ethereum && window.ethereum.isMacro) {
  // User is on Macro Browser
  console.log('Macro detected');
}

Provider Properties

window.ethereum.isMacro // true
window.ethereum.version // "1.0.0"
window.ethereum.privacyFeatures // ["signingPolicy", "mixer", "privateSwaps"]

Requesting Account Access

Standard EIP-1102:

const accounts = await window.ethereum.request({
  method: 'eth_requestAccounts'
});

Macro-specific behavior: User sees signing sandbox translation of connection request.

Sending Transactions

Standard transaction:

const txHash = await window.ethereum.request({
  method: 'eth_sendTransaction',
  params: [{
    from: userAddress,
    to: contractAddress,
    data: encodedData,
    value: '0x0'
  }]
});

Macro behavior:

  • Transaction intercepted by Signing Sandbox

  • Decoded to plain English

  • Policy check performed

  • User shown risk assessment

  • User approves/rejects

Signing Messages

Personal sign:

const signature = await window.ethereum.request({
  method: 'personal_sign',
  params: [message, address]
});

Typed data (EIP-712):

const signature = await window.ethereum.request({
  method: 'eth_signTypedData_v4',
  params: [address, typedData]
});

Macro enhancement: Typed data displayed in human-readable format.

Privacy-Enhanced Features

Use Macro's privacy APIs for enhanced user experience.

Check Privacy Features

const features = await window.ethereum.request({
  method: 'macro_getPrivacyFeatures'
});

// Returns:
// {
//   mixer: true,
//   privateSwaps: true,
//   signingPolicy: true,
//   vpn: true
// }

Request Private Transaction

const txHash = await window.ethereum.request({
  method: 'macro_sendPrivateTransaction',
  params: [{
    from: userAddress,
    to: recipientAddress,
    value: amount,
    privacy: 'mixer' // or 'direct' or 'flashbots'
  }]
});

Macro routes through privacy mixer automatically.

Request Private Swap

const swapResult = await window.ethereum.request({
  method: 'macro_privateSwap',
  params: [{
    fromToken: tokenAddressA,
    toToken: tokenAddressB,
    amount: swapAmount,
    slippage: 0.5 // 0.5%
  }]
});

MEV-protected swap execution.

Full API Reference

Best Practices

Clear Communication

  • Explain what permissions you're requesting

  • Use EIP-712 for structured data (better UX in Macro)

  • Minimize permission scope

Respect User Privacy

  • Don't request unnecessary wallet connections

  • Limit data collection

  • Support Macro's privacy features

Optimize for Signing Sandbox

  • Use descriptive function names in contracts

  • Verify contracts on Etherscan (better UX)

  • Provide clear transaction context

Test with Different Policies

  • Test when user has strict signing policies

  • Handle rejection gracefully

  • Provide clear error messages

Debugging

Check Connection

console.log(window.ethereum.isConnected()); // true/false

Listen for Events

window.ethereum.on('accountsChanged', (accounts) => {
  console.log('Account changed:', accounts);
});

window.ethereum.on('chainChanged', (chainId) => {
  console.log('Network changed:', chainId);
});

Error Handling

try {
  const tx = await window.ethereum.request({...});
} catch (error) {
  if (error.code === 4001) {
    // User rejected in signing sandbox
  } else if (error.code === -32002) {
    // Request pending
  }
}

Testing

Test on Macro:

  1. Download Macro Browser

  2. Create test Privacy Profile

  3. Connect wallet to testnet

  4. Test your dApp integration

  5. Try different signing policies (Settings → Signing Sandbox)

Performance Optimization Guide


Standard Web3 APIs. Privacy-enhanced features optional.

Last updated