# Web3 API Reference

***

## <mark style="color:purple;">Web3 API Reference</mark>

Complete API reference for Web3 integration with Macro.

### <mark style="color:purple;">Standard Ethereum Provider API</mark>

Macro implements EIP-1193. All standard Ethereum provider methods supported.

#### eth\_requestAccounts

Request user's wallet address.

```javascript
const accounts = await ethereum.request({
  method: 'eth_requestAccounts'
});
// Returns: ['0x...']
```

#### eth\_accounts

Get currently connected accounts.

```javascript
const accounts = await ethereum.request({
  method: 'eth_accounts'
});
```

#### eth\_sendTransaction

Send a transaction.

```javascript
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.

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

#### eth\_signTypedData\_v4

Sign typed structured data (EIP-712).

```javascript
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.

```javascript
await ethereum.request({
  method: 'wallet_switchEthereumChain',
  params: [{ chainId: '0x1' }] // Mainnet
});
```

#### wallet\_addEthereumChain

Add custom network.

```javascript
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']
  }]
});
```

### <mark style="color:purple;">Macro-Specific API</mark>

**Privacy-enhanced methods:**

#### macro\_getPrivacyFeatures

Check available privacy features.

```javascript
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.

```javascript
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 mixing
```

**Parameters:**

* `privacy`: Routing method (mixer, flashbots, or direct)
* `mixerDelay`: Delay before withdrawal (seconds, optional)

#### macro\_privateSwap

Execute MEV-protected swap.

```javascript
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.

```javascript
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.

```javascript
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.

```javascript
const profile = await ethereum.request({
  method: 'macro_getCurrentProfile'
});

// Returns:
// {
//   name: 'Degen',
//   id: 'profile_abc123',
//   color: '#9333EA'
// }
```

### <mark style="color:purple;">Events</mark>

**Listen for Macro-specific events:**

#### profileChanged

Fires when user switches Privacy Profile.

```javascript
ethereum.on('profileChanged', (profile) => {
  console.log('New profile:', profile.name);
  // Disconnect and require re-connection
});
```

#### vpnStatusChanged

Fires when VPN status changes.

```javascript
ethereum.on('vpnStatusChanged', (status) => {
  console.log('VPN now:', status.enabled);
});
```

#### signingPolicyUpdated

Fires when user updates signing policy for your dApp.

```javascript
ethereum.on('signingPolicyUpdated', (policy) => {
  console.log('New policy:', policy);
});
```

### <mark style="color:purple;">Error Codes</mark>

**Macro-specific error codes:**

| Code | Meaning                                                  |
| ---- | -------------------------------------------------------- |
| 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:**

```javascript
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

***
