Skip to content

Instantly share code, notes, and snippets.

@danfinlay
Created October 5, 2018 04:40
Show Gist options
  • Save danfinlay/4b6c74d0a16da22d5c877ca0e989016e to your computer and use it in GitHub Desktop.
Save danfinlay/4b6c74d0a16da22d5c877ca0e989016e to your computer and use it in GitHub Desktop.
Quick mockup for a simple plugin system
console.log('plugin loaded!')
window.parent.postMessage('PLUGIN ping', '*', false)
window.addEventListener('message', function (e) {
console.log('PLUGIN RECEIVED', e )
window.parent.postMessage('PLUGIN pong', '*', false)
})
// A plugin is a function that receives a metamask plugin API:
function MetaPlugin (pluginApi) {
console.log('calling plugin func!')
// A plugin returns an object that adheres to the MetaPlugin protocol:
return {
// A MetaPlugin includes a getApi() method that returns an API object.
getApi() {
return {
// Let's imagine the protocol requires the API to provide a getName() method.
getName() {
console.log('sandboxed plugin getting name...')
return 'test plugin'
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment