@dsponsor/sdk
v5.0.2
Published
SDK for DSponsor integration
Downloads
1,367
Readme
DSponsor SDK
DSponsor SDK is a library that allows you to easily integrate DSponsor into your app.
It facilitates the creation, management, and interaction with smart contracts for advertising and sponsorship.
Uses the Ethereum library ethers.js.
CDN :
<script src="https://unpkg.com/@dsponsor/sdk"></script>
HTML example :
<html>
<head>
<title>Home</title>
<script type="module">
import { AdSpaceRenderer } from 'https://unpkg.com/@dsponsor/sdk';
const sponsoredItem = AdSpaceRenderer.fromOffer(23, {
selector: 'dsponsor',
})
await sponsoredItem.connect();
console.log('Connected to the contract');
await sponsoredItem.preload();
const container = sponsoredItem.render({theme: 'blue'});
document.getElementById('dsponsor').appendChild(container );
</script>
</head>
<body>
<div id="dsponsor"></div>
</body>
</html>
Quick Start
import DSponsorSDK from '@dsponsor/sdk';
// Initialize with default settings (Polygon Mumbai)
// Will use a new private key if not provided
const dsponsorSDK = new DSponsorSDK();
// For custom configuration, pass the desired chain and private key
const customDsponsorSDK = new DSponsorSDK({
chain: new ChainNetwork({...}),// Custom chain network - default to Polygon Mumbai
privateKey: 'your-private-key-here', // Optional for signing transactions
});
const renderer = dsponsorSDK.getAdSpaceRenderer({
offerId: 23,// Offer ID to render
selector: 'dsponsor_div',
selection: 'grid 2x2'
});
//await renderer.connect(); // Connect to the signer (e.g., Metamask) for transactions (on browser)
await renderer.preload(); // Preload ad data
const container = renderer.render();
document.getElementById('dsponsor').appendChild(container);
After initializing DSponsorSDK, you can interact with the DSponsor ecosystem:
// Get the address of the DSponsorAdmin contract
const dsponsorAdmin = dsponsorSDK.getDSponsorAdmin();
// Example: Fetching the base point share (BPS) value
async function fetchBPS() {
const bps = await dsponsorAdmin.getFeeBPS();
console.log(`Current BPS: ${bps}`);
}
fetchBPS();
API Reference
- Getting started
- Creators - Quick start
- Integrations - Quick start
- API Reference