# Integration Guide

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

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

![Diagram 1](https://content.gitbook.com/content/12iOS9xiOBrGJgaaBtCR/blobs/bqcynsh55k9LEndZDC0j/Screenshot_1.png)

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

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

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

**Check for Macro:**

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

#### Provider Properties

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

### <mark style="color:purple;">Requesting Account Access</mark>

**Standard EIP-1102:**

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

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

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

**Standard transaction:**

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

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

**Personal sign:**

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

**Typed data (EIP-712):**

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

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

### <mark style="color:purple;">Privacy-Enhanced Features</mark>

**Use Macro's privacy APIs for enhanced user experience.**

#### Check Privacy Features

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

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

#### Request Private Transaction

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

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

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

#### 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

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

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

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

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

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

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

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

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

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

**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.
