# Moojo Ads SDK

This README provides instructions on how to use the Moojo Ads SDK for displaying ads in your application.

## Installation

The Moojo Ads SDK is available on npm. You can install it using npm or yarn:

```bash
npm install @moojo/moojo-ads-sdk
# or
yarn add @moojo/moojo-ads-sdk
```

## Usage

### Initialize Moojo Ads

To initialize the MoojoAdsSDK, you need to provide the following parameters:

| Parameter        | Description                                                                    | Required |
| ---------------- | ------------------------------------------------------------------------------ | -------- |
| userPrivateKey   | The user's private key, a unique identifier used to encrypt their data.        | Yes      |
| appWalletAddress | Your application's private wallet address, used to collect your revenue share. | Yes      |
| options          | Configuration options (network, debug mode).                                   | No       |

#### Generating User Keys

Moojo generates the user's private key using their unique identifier. Use your internal user ID in the following way:

```javascript
import { MoojoAdsSdk, userKeys, PrivateKey } from '@moojo/moojo-ads-sdk'

const INTERNAL_USER_ID = '4343' // Replace with your own internal ID
const userPrivateKey = userKeys.privateKeyForSecret(INTERNAL_USER_ID)
const publicKey = privateKey.createPublic()
```

**Note:** The internal user ID should remain confidential and consistent for each user across login sessions.

#### Initializing the SDK

After obtaining the user's key, initialize the SDK:

```javascript
import { MoojoAdsSdk, userKeys, PrivateKey } from '@moojo/moojo-ads-sdk'

// Setting up your dApp wallet address
const appWalletAddress = '0x1234...' // Replace with your own wallet address

// Create an instance of MoojoAdsSdk
const moojoAdsSdk = new MoojoAdsSdk(userPrivateKey, appWalletAddress, {
  network: 'mainnet',
  debug: false,
})
```

### Retrieving Matching Ads

To load all ads that match the current user:

```javascript
const matchingAds = await moojoAdsSdk.listAds()
```

### Filtering and Displaying Ads

To loop through the list of ads and, for example, print names of 'native' ads:

```javascript
const matchingAds = await moojoAdsSdk.listAds()

matchingAds.filter(ad => ad.tag === 'native').forEach(ad => console.log(ad.name))
```

## Configuration Options

When initializing the SDK, you can provide the following options:

- `network`: 'testnet' or 'mainnet'
- `debug`: true or false

## Additional Information

For more detailed information about the Moojo Ads SDK, please refer to our [official documentation](https://docs.moojo.xyz/publishers-and-app-devs/the-moojo-ads-sdk).

## License

This project is licensed under the [MIT License](../../LICENSE).
