npm

test-ad-sdk
TypeScript icon, indicating that this package has built-in type declarations

0.0.6 • Public • Published

SDK Integration Guide

Welcome to the SDK Integration Guide! This document will help you get started with integrating our SDK into your project.

Table of Contents

Introduction

This Adbazaar SDK allows publishers to display adds on there respective websites by integrating our get advertisement features into their website. With our SDK, you can:

  • Get Advertisement
  • Advertisements shown based on the profile of the user(coming from third party service linkko)

Requirements

Before you begin, ensure you have the following prerequisites:

  • Node.js (v16 or above)
  • Node package manager (for installing node dependencies)
  • Internet connection

Installation

For intalling the sdk on your machine use the below command :

npm i test-ad-sdk

Once the installation is successfull you are ready to configure the package

Configuration

Configure the arguments passed to the getAdvertisement function Here are the list of arguments passed to the getAdvertisement

  • publisherContractAddress : The contract address of the publisher
  • adSpaceId : The adSpace on which the publisher wants the ads to be displayed
  • userWalletAddress : The wallet address of the user for which the ads has to be shown(note : this address is used for fetching the user profile from linkko)

Usage

Here is step by step guide for usage:

  1. Import the package using the import statement
import { getAdvertisement } from 'test-ad-sdk';
  1. Now configure the getAdvertisement variables accordingly
const publisherContractAddress  = 'your_publisher_contract_address'
const adSpaceId = 'your_ad_space_id'
const userWalletAddress = 'your_user_wallet_address'
  1. Call the getAdvertisement function from the sdk to get the ads
const result : any = await getAdvertisement(publisherContractAddress, adSpaceId, userWalletAddress)
return result
  1. Call the getAdvertisementBySize function from sdk to get the imageUrl by providing the respective dimension.
const result : any = await getAdvertisementBySize(publisherContractAddress, adSpaceId, dimension, userWalletAddress)
return result

Usage Summary

  1. Usage summary to fetch getAdvertisement.
import { getAdvertisement } from'test-ad-sdk'; 
const publisherContractAddress = 'your_publisher_contract_address';
const adSpaceId = 'your_ad_space_id';
const userwalletAddress = 'your_user_wallet_address';

async function fetchAdvertisement(): Promise<any> {
    try {
        const result: any = await getAdvertisement(publisherContractAddress, adSpaceId, userwalletAddress);
        return result;
    } catch (error) {
        throw error;
    }
}

// Example Usage
fetchAdvertisement()
    .then(result => {
        console.log("Advertisement fetched successfully:", result);
    })
    .catch(error => {
        console.error("Failed to fetch advertisement:", error);
    });

NOTE: To export the fetchAdvertisement function using export default in TypeScript, you can modify the function definition and export statement accordingly.

import { getAdvertisement } from 'test-ad-sdk';

const publisherContractAddress = 'your_publisher_contract_address';
const adSpaceId = 'your_ad_space_id';
const userwalletAddress = 'your_user_wallet_address';

async function fetchAdvertisement(): Promise<any> {
    try {
        const result: any = await getAdvertisement(publisherContractAddress, adSpaceId, userwalletAddress);
        console.log("selected ad details", result);
        return result;
    } catch (error) {
        console.error("Error fetching advertisement:", error);
        throw error;
    }
}

export default fetchAdvertisement;
  1. Usage summary to fetch getAdvertisementBySize.
import { getAdvertisementBySize } from'test-ad-sdk'; 
const publisherContractAddress = 'your_publisher_contract_address';
const adSpaceId = 'your_ad_space_id';
const userwalletAddress = 'your_user_wallet_address';
const dimension = 'your_dimension'   //e.g '300x250'

async function fetchAdvertisementBySize(): Promise<any> {
    try {
        const result: any = await getAdvertisementBySize(publisherContractAddress, adSpaceId, dimension, userwalletAddress);
        return result;
    } catch (error) {
        throw error;
    }
}

// Example Usage
fetchAdvertisementBySize()
    .then(result => {
        console.log("ImageUrl fetched successfully:", result);
    })
    .catch(error => {
        console.error("Failed to fetch advertisementBySize:", error);
    });

Output

  • Sample output of getAdvertisement function
  {
      adDetails: {
        '0': {
          deviceType: 1,
          dimension: '320x100',
          ipfsUrl: 'ipfs.io/ipfs/QmPw3gQMK73CeVD3fVstHicH51cy5bnG4wJKji6tuyBL7Y/Banner%20320x100.png'
        },
        '1': {
          deviceType: 1,
          dimension: '728x90',
          ipfsUrl: 'ipfs.io/ipfs/QmPw3gQMK73CeVD3fVstHicH51cy5bnG4wJKji6tuyBL7Y/Nike%20Leaderboard%20728x90.png'
        },
        '2': {
          deviceType: 1,
          dimension: '300x250',
          ipfsUrl: 'ipfs.io/ipfs/QmPw3gQMK73CeVD3fVstHicH51cy5bnG4wJKji6tuyBL7Y/Nike%20Medium%20Rectangle%20300x250.png'
        },
        '3': {
          deviceType: 1,
          dimension: '120x600',
          ipfsUrl: 'ipfs.io/ipfs/QmPw3gQMK73CeVD3fVstHicH51cy5bnG4wJKji6tuyBL7Y/Nike%20Skycraper%20120x600_2.png'
        },
        advertiser: '0x659bC276EfCD11e42627ee4A2A47A38CF59E6da9',
        adTitle: 'Stack Overflow: AI',
        adText: 'AI power your knowledge community',
        adStatus: 1,
        payRatePerSecond: 57870370370370n,
        adLink: 'https://stackoverflow.co/teams/ai/?utm_medium=ppc&utm_source=house-ads&utm_campaign=teams-overflowai-launch',
        adSpaceSizes: [
          '0x3132307836303000000000000000000000000000000000000000000000000000',
          '0x3332307831303000000000000000000000000000000000000000000000000000',
          '0x3732387839300000000000000000000000000000000000000000000000000000',
          '0x3438307836300000000000000000000000000000000000000000000000000000',
          '0x3330307832353000000000000000000000000000000000000000000000000000'
        ],
        walletPersonas: [ 'Rewards' ],
        adId: '0xe038abb0d09d86ac5b16a2a78138a5400e30ea65316108b41ee268df23023cb9',
        balance: 74745486111111848740n,
        weight: 100
      }
    }

NOTE: In the above output use the ipfsUrl for displaying the ads with different ad dimensions.

  • Sample output of getAdvertisementBySize function
    • If the image with provided dimension exists

      {
          adDetails: {
              imageUrl: 'ipfs.io/ipfs/QmPw3gQMK73CeVD3fVstHicH51cy5bnG4wJKji6tuyBL7Y/Nike%20Medium%20Rectangle%20300x250.png'
            }
        }
    • If the image with provided dimension doesn't exists

      {
            adDetails: {
              '0': {
                deviceType: 1,
                dimension: '320x100',
                ipfsUrl: 'ipfs.io/ipfs/QmPw3gQMK73CeVD3fVstHicH51cy5bnG4wJKji6tuyBL7Y/Banner%20320x100.png'
              },
              '1': {
                deviceType: 1,
                dimension: '728x90',
                ipfsUrl: 'ipfs.io/ipfs/QmPw3gQMK73CeVD3fVstHicH51cy5bnG4wJKji6tuyBL7Y/Nike%20Leaderboard%20728x90.png'
              },
              '2': {
                deviceType: 1,
                dimension: '300x250',
                ipfsUrl: 'ipfs.io/ipfs/QmPw3gQMK73CeVD3fVstHicH51cy5bnG4wJKji6tuyBL7Y/Nike%20Medium%20Rectangle%20300x250.png'
              },
              '3': {
                deviceType: 1,
                dimension: '120x600',
                ipfsUrl: 'ipfs.io/ipfs/QmPw3gQMK73CeVD3fVstHicH51cy5bnG4wJKji6tuyBL7Y/Nike%20Skycraper%20120x600_2.png'
              },
              advertiser: '0x659bC276EfCD11e42627ee4A2A47A38CF59E6da9',
              adTitle: 'Stack Overflow: AI',
              adText: 'AI power your knowledge community',
              adStatus: 1,
              payRatePerSecond: 57870370370370n,
              adLink: 'https://stackoverflow.co/teams/ai/?utm_medium=ppc&utm_source=house-ads&utm_campaign=teams-overflowai-launch',
              adSpaceSizes: [
                '0x3132307836303000000000000000000000000000000000000000000000000000',
                '0x3332307831303000000000000000000000000000000000000000000000000000',
                '0x3732387839300000000000000000000000000000000000000000000000000000',
                '0x3438307836300000000000000000000000000000000000000000000000000000',
                '0x3330307832353000000000000000000000000000000000000000000000000000'
              ],
              walletPersonas: [ 'Rewards' ],
              adId: '0xe038abb0d09d86ac5b16a2a78138a5400e30ea65316108b41ee268df23023cb9',
              balance: 55766261574074933170n,
              weight: 100,
              imageUrl: null
            }
          }

References

Below are the screenshot of references to get the following parameters:

const publisherContractAddress  = 'your_publisher_contract_address'
const adSpaceId = 'your_ad_space_id'
const userWalletAddress = 'your_user_wallet_address'
  1. Visit the website https://adbazaar.vercel.app/

  2. Once you are on the website select Enter as a Publisher.

Alt text

  1. Now select ManageAdspace.

Alt text

  1. Now copy the publisherContractAddress and adSpaceId from the clipboard

Alt text

NOTE: For user wallet address provide the wallet address that you are using to show the ads on.

Contact

For further assistance, please reach out to our support team.

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.0.61latest

Version History

VersionDownloads (Last 7 Days)Published
0.0.61
0.0.50
0.0.40
0.0.30
0.0.20
0.0.10

Package Sidebar

Install

npm i test-ad-sdk

Weekly Downloads

0

Version

0.0.6

License

ISC

Unpacked Size

356 kB

Total Files

13

Last publish

Collaborators

  • vishal101