Welcome to the SDK Integration Guide! This document will help you get started with integrating our SDK into your project.
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)
Before you begin, ensure you have the following prerequisites:
- Node.js (v16 or above)
- Node package manager (for installing node dependencies)
- Internet connection
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
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)
Here is step by step guide for usage:
- Import the package using the import statement
import { getAdvertisement } from 'test-ad-sdk';
- Now configure the getAdvertisement variables accordingly
const publisherContractAddress = 'your_publisher_contract_address'
const adSpaceId = 'your_ad_space_id'
const userWalletAddress = 'your_user_wallet_address'
- Call the getAdvertisement function from the sdk to get the ads
const result : any = await getAdvertisement(publisherContractAddress, adSpaceId, userWalletAddress)
return result
- 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 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;
- 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);
});
- 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 } }
-
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'
-
Visit the website https://adbazaar.vercel.app/
-
Once you are on the website select Enter as a Publisher.
- Now select ManageAdspace.
- Now copy the publisherContractAddress and adSpaceId from the clipboard
NOTE: For user wallet address provide the wallet address that you are using to show the ads on.
For further assistance, please reach out to our support team.