@credenza3/scanner-evm
v0.0.4
Published
Credenza Scanner for EVM
Downloads
41
Readme
Credenza3 Scanner EVM
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 @credenza3/scanner-evm
with yarn
yarn add @credenza3/scanner-evm
with pnpm
pnpm install @credenza3/scanner-evm
or include a script tag
<script src="https://unpkg.com/@credenza3/scanner-evm/dist/scanner.umd.js"></script>
Usage
import {Scanner} from '@credenza3/scanner-evm'
or
const Scanner = window.CredenzaScannerEvm
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')
})