Minter Connect is a library that provides connection between your web application and Minter Link extension.
With Minter Connect you can connect your website to extension, get access to user wallet address, implement Minter authentication and even make one-click payment requests.
Check Minter Link Playground for live demo.
npm install minter-connect
Minter Connect takes optional merchant name
parameter on initialization.
import MinterConnect from 'minter-connect'
const minterConnect = new MinterConnect('My website')
Following events are available for subscription:
- MinterLinkObservableProps.IsInstalled
- MinterLinkObservableProps.IsUnlocked
- MinterLinkObservableProps.Version
- MinterLinkObservableProps.Wallet
import { MinterLinkObservableProps } from 'minter-connect'
minterConnect.subscribe(MinterLinkObservableProps.IsInstalled, (value: boolean) => {
console.log('Extension installed:', value)
})
minterConnect.subscribe(MinterLinkObservableProps.IsUnlocked, (value: boolean) => {
console.log('Extension unlocked:', value)
})
minterConnect.subscribe(MinterLinkObservableProps.Version, (value: string) => {
console.log('Extension version:', value)
})
minterConnect.subscribe(MinterLinkObservableProps.Wallet, (value: string) => {
console.log('Active Wallet:', value)
})
Request permanent access to user's active wallet:
minterConnect.connectRequest()
.then((wallet: string) => {
// Connect accepted, wallet address returned
console.log(wallet)
})
.catch((e) => {
// Connect rejected
console.error(e)
})
Request message, signed with connected wallet private key:
import { SignResponse } from 'minter-connect'
minterConnect.signRequest('Message')
.then((signature: string) => {
// ECDSA Signature (0x-prefixed hex string)
console.log(signature)
})
.catch(() => {
// Sign rejected
console.error(e)
})
Prepare payment request data & await for response from user:
const data = {
address: 'Mx...', // Payment address
amount: 1, // Payment amount
coin: 'BIP', // Payment coin
payload: 'Order #1' // Any custom payload up to 1024 bytes
}
minterConnect.paymentRequest(data)
.then((hash: string) => {
// Payment accepted, transaction hash returned
console.log(hash)
})
.catch(() => {
// Payment rejected
console.error(e)
})