@credenza-web3/scanner
v0.3.8
Published
Credenza Scanner
Downloads
92
Readme
Credenza3 Scanner
Ethers.js
Ethers.js v6 is required
<script src="https://cdnjs.cloudflare.com/ajax/libs/ethers/6.0.8/ethers.umd.min.js" integrity="sha512-B/0gQMZc/py0Ldqgnuen4yZzABN1sz6dv65+2pVQHgOlIcrshSTJsk7yCSWqh0wh94KUD4Lr5F4HSWzcZjhqqw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
Installation
with npm
npm install @credenza-web3/scanner
with yarn
yarn add @credenza-web3/scanner
with pnpm
pnpm install @credenza-web3/scanner
or include a script tag
<script src="https://unpkg.com/@credenza-web3/scanner/dist/scanner.umd.js"></script>
Usage
import {Scanner} from '@credenza-web3/scanner'
or
const Scanner = window.CredenzaScanner
Create an instance of Credenza scanner
const scanner = new Scanner({target: '.scanner-placeholder'}) // query selector to render the scanner into.
Static
Scanner.events
- list of events produced by scanner
Get a list of available video input devices
await scanner.listVideoInputDevices()
Scan
scanner.scan({
deviceId?: string,
isCloseButton?: boolean
maxScansPerSecond? number // 25
}) // (await scanner.listVideoInputDevices())[0].id by default
Cancel
scanner.close()
Events
On capture
// 'capture'
scanner.on(Scanner.events.CAPTURE, ({ rawString, message, userAddress, scanType, chainId }) => {
console.log('Scan completed', { rawString, message, userAddress })
})
On error
// 'error'
scanner.on(Scanner.events.ERROR, (err) => {
console.log('Scan error:', err)
})
On cancel
// 'cancel'
scanner.on(Scanner.events.CAPTURE, () => {
console.log('Scan canceled')
})