This README provides instructions on how to use the Moojo Ads SDK for displaying ads in your application.
The Moojo Ads SDK is available on npm. You can install it using npm or yarn:
npm install @moojo/moojo-ads-sdk
# or
yarn add @moojo/moojo-ads-sdk
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 |
Moojo generates the user's private key using their unique identifier. Use your internal user ID in the following way:
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.
After obtaining the user's key, initialize the SDK:
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,
})
To load all ads that match the current user:
const matchingAds = await moojoAdsSdk.listAds()
To loop through the list of ads and, for example, print names of 'native' ads:
const matchingAds = await moojoAdsSdk.listAds()
matchingAds.filter(ad => ad.tag === 'native').forEach(ad => console.log(ad.name))
When initializing the SDK, you can provide the following options:
-
network
: 'testnet' or 'mainnet' -
debug
: true or false
For more detailed information about the Moojo Ads SDK, please refer to our official documentation.
This project is licensed under the MIT License.