> ## Documentation Index
> Fetch the complete documentation index at: https://docs.skale.space/llms.txt
> Use this file to discover all available pages before exploring further.

# MPP SDK

> SDK for JavaScript and TypeScript developers to enable private, gasless payments on SKALE using MPP (Machine Payments Protocol)

<Note>
  The MPP SDK is compatible with both JavaScript and TypeScript in Node.js, Bun, and browser environments.
  [![npm version](https://img.shields.io/npm/v/%40skalenetwork%2Fmpp)](https://www.npmjs.com/package/@skalenetwork/mpp)
  If you have any issues, please join us in [Discord](https://discord.gg/skale) or open an issue on [GitHub](https://github.com/skalenetwork/mpp-sdk).
</Note>

Currency identifiers in this page use exact onchain values (e.g., `USDC.e` on SKALE Base, `eUSDC` on SKALE Base Sepolia). In your UI you can display a normalized label like `USDC`.

## Overview

The MPP SDK enables developers to integrate private, gasless payments into their applications on the SKALE Network. It provides support for:

* **Standard transfers** on SKALE Base
* **Gasless payments** via EIP-3009 and EIP-2612 permits
* **Encrypted transaction amounts** via threshold encryption
* **Confidential tokens** for native privacy

## Installation

```bash theme={null}
# npm
npm install @skalenetwork/mpp

# yarn
yarn add @skalenetwork/mpp

# pnpm
pnpm add @skalenetwork/mpp

# bun
bun add @skalenetwork/mpp
```

## Quick Start

### Client-Side Usage

```typescript theme={null}
import { mpp } from '@skalenetwork/mpp/client'

// Standard transfer on SKALE Base
const method = mpp.charge({
  chain: 'skale-base',
  currency: 'USDC.e'
})

// Gasless with EIP-3009
const gaslessMethod = mpp.charge({
  chain: 'skale-base',
  currency: 'USDC.e',
  extensions: { gasless: 'eip3009' }
})

// Encrypted transaction amounts via threshold encryption
const encryptedMethod = mpp.charge({
  chain: 'skale-base',
  currency: 'USDC.e',
  extensions: { skale: { encrypted: true } }
})

// Confidential token with native privacy + gasless
const confidentialMethod = mpp.charge({
  chain: 'skale-base-sepolia',
  currency: 'eUSDC',
  extensions: {
    skale: { encrypted: true, confidentialToken: true },
    gasless: 'eip3009'
  }
})
```

### Server-Side Usage

```typescript theme={null}
import { mpp } from '@skalenetwork/mpp/server'

const method = mpp.charge({
  chain: 'skale-base',
  currency: 'USDC.e',
  extensions: { gasless: 'eip3009' }
})

// In your MPPx server setup
const mppx = Mppx.create({
  methods: [method],
  realm: 'api.example.com',
  secretKey: process.env.MPP_SECRET
})
```

<Warning>
  `MPP_SECRET` is a server-only secret — generate a long random value, store it in your server environment, and never expose it in client-side code or commit it to your repository.
</Warning>

## Supported Chains

| Chain                | Network                    | Chain ID   |
| -------------------- | -------------------------- | ---------- |
| `skale-base`         | SKALE Base Mainnet         | 1187947933 |
| `skale-base-sepolia` | SKALE Base Sepolia Testnet | 324705682  |
| `base`               | Base Mainnet               | 8453       |
| `base-sepolia`       | Base Sepolia               | 84532      |

## API Reference

### `mpp.charge(options)`

Creates a payment method for MPP integration.

**Parameters:**

* `chain: string | Chain` – Chain identifier (string) or custom viem `Chain` object
* `currency: string | CurrencyConfig` – Currency identifier or custom configuration
* `extensions?: object` – Optional extensions for gasless and privacy features

**Returns:** `PaymentMethod` – Configured payment method for MPP

### Extensions

#### Gasless Payments

Enable gasless transactions using EIP-3009 or EIP-2612. Users can pay without holding the native gas token (sFUEL/ETH) — transaction fees are deducted from the token being transferred.

```typescript theme={null}
extensions: { gasless: 'eip3009' }  // EIP-3009 transfer with authorization
extensions: { gasless: 'eip2612' }  // ERC-2612 permit
extensions: { gasless: true }       // Auto-detect EIP-3009
```

#### Encrypted Transaction Amounts

Encrypt transaction amounts onchain using threshold encryption. Amounts are hidden in the mempool until execution, then visible on the ledger. Requires a SKALE chain with Programmable Privacy.

```typescript theme={null}
extensions: { skale: { encrypted: true } }
```

#### Confidential Tokens

Use native confidential tokens with fully shielded balances and transaction amounts that remain private even onchain. Currently available on SKALE Base Sepolia with tokens like `eUSDC`.

```typescript theme={null}
extensions: {
  skale: {
    encrypted: true,
    confidentialToken: true
  }
}
```

## Payment Strategies

The SDK supports various combinations of features:

| Chain              | Currency | Gasless | Encrypted | Confidential Token |
| ------------------ | -------- | ------- | --------- | ------------------ |
| skale-base         | USDC.e   | ✓       | Optional  | No                 |
| skale-base-sepolia | eUSDC    | ✓       | Always    | Yes                |

* **Gasless**: EIP-3009 transfer with authorization, eliminating gas fees
* **Encrypted**: Transaction "to" address and amounts encrypted in the mempool, visible on the ledger after execution
* **Confidential Token**: Native confidential tokens (e.g., eUSDC) provide fully shielded balances and amounts that remain private even onchain

<Note>
  Confidential Tokens and Re-encryption are currently in Beta on SKALE Base Sepolia. Encrypted Transactions and Conditional Transactions are available on both SKALE Base and SKALE Base Sepolia.
</Note>

## Custom Chains

You can use any viem `Chain` object for custom chain configurations:

```typescript theme={null}
import { mpp } from '@skalenetwork/mpp/client'
import { defineChain } from 'viem'

const myChain = defineChain({
  id: 123456,
  name: 'My Chain',
  nativeCurrency: { name: 'ETH', symbol: 'ETH', decimals: 18 },
  rpcUrls: {
    default: { http: ['https://mychain.rpc'] }
  }
})

const method = mpp.charge({
  chain: myChain,
  currency: {
    address: '0xTokenAddress...',
    symbol: 'TOKEN',
    decimals: 18,
    eip3009: true
  }
})
```

<Warning>
  Custom chains support **standard ERC-20 transfers** and **EIP-3009 gasless payments** only. Encrypted amounts and confidential tokens require built-in chain configurations with specific contract addresses.
</Warning>

## Best Practices

### Choosing the Right Configuration

Pick the simplest setup that meets your privacy and UX needs. Standard transfers are fastest and most cost-effective; full privacy configurations provide maximum confidentiality.

### Testing

Always test payment flows on testnet before mainnet deployment:

* Use `skale-base-sepolia` for testing
* Verify gasless transactions work with your token contracts
* Test encrypted transaction decryption and retrieval

## Browser Compatibility

<Note>
  When using the SDK in browser environments, you may need to polyfill `Buffer`. Install the buffer package and configure your bundler:

  ```bash theme={null}
  npm install buffer
  ```

  For **Vite**, add to your `vite.config.ts`:

  ```typescript theme={null}
  import { defineConfig } from 'vite'

  export default defineConfig({
    resolve: {
      alias: {
        buffer: 'buffer',
      },
    },
  })
  ```

  For **Webpack 5**, add to your `webpack.config.js`:

  ```javascript theme={null}
  module.exports = {
    resolve: {
      fallback: {
        buffer: require.resolve('buffer/'),
      },
    },
  }
  ```
</Note>

## Resources

* **GitHub:** [https://github.com/skalenetwork/mpp-sdk](https://github.com/skalenetwork/mpp-sdk)
* **MPP Protocol:** [https://mpp.dev/](https://mpp.dev/)
