Overview
The Mash SDK is a client-side library that can be used to interact with the Mash consumer wallet. You can use it in conjunction with Mash monetization settings to charge for different categories of pricing, provide freebies, and see if a user has free access after spending a certain amount.
You can charge for any event or action – from visiting a page, scrolling to a certain point, clicking a button, or time engaging with content. You can also trigger auto-payments for users that have budgets setup.
NPM Package
To help with development, we’ve open-sourced an NPM package to more easily build with Mash.
Installing
To install the SDK on your site, add the following script to the header of the page.
When the scripts loads it will attach Mash
to the window
object on the current page.
<script src="https://wallet.getmash.com/sdk/sdk.js"></script>
API
init
Initializes the Mash consumer wallet on the page.
// Type Definition
type MashSettings = {
id: string; // Earner account ID
}
window.Mash.init(settings: MashSettings): Promise<void>
// Example
const settings = { id: "earner-id" }
window.Mash.init(id).then(() => alert("Wallet Configured"))
hasAccess
Check to see if the user has access to the given resource. If the user does not have access, it will trigger the payment flow through the Mash consumer wallet.
// Type Definition
window.Mash.hasAccess(resourceID: string): Promise<boolean>
// Example
window.Mash.hasAccess("resource-id").then(hasAccess => {
if (hasAccess) {
alert("User has access")
return
}
})
donate
Triggers Mash donation flow in Mash consumer wallet.
// Type Definition
window.Mash.donate(): Promise<void>
// Example
window.Mash.donate().then(() => alert("Thanks for the donation"))
userHasValidBudget
Checks if the user logged into their consumer wallet has configured a budget for your site. Budgets allow users to pre-authorize payments and reduce the amount of user interaction is required for payments.
// Type Definition
window.Mash.userHadValidBudget(resourceID: string): Promise<boolean>
// Example
window.Mash.userHasValidBudget("resource-id").then(result => alert(`Does user have a budget: ${result}`))
isReady
Checks if the Mash wallet is initialized on the page.
// Type Definition
window.Mash.isReady(): boolean
// Example
window.Mash.isReady().then(result => alert(`Is Mash Wallet ready: ${result}`))