On this page
Getting Started
Connect the provider before signing. The transaction examples use the algosdk 2-style from/to fields; match the SDK major version you install. algodClient, addresses, and grouped transactions must be prepared before running the snippets. Browser examples using Buffer need an explicit buffer import or an equivalent base64 encoder.
Learn how to detect, connect, and interact with Algorand using OneKey’s provider.
OneKey’s Algorand provider supports both legacy and ARC-0001 compliant interfaces.
Provider Detection
// Detect OneKey Algorand provider
const provider = window.$onekey?.algo
if (!provider) {
throw new Error('OneKey Algorand provider not detected')
}
// Check compatibility
console.log('isOneKey:', provider.isOneKey) // trueConnect (Legacy API)
const { address } = await provider.connect()
console.log('Connected:', address)
// Check connection status
console.log('isConnected:', provider.isConnected)
console.log('Address:', provider.address)Enable (ARC-0001)
const result = await provider.enable({
genesisID: 'mainnet-v1.0',
genesisHash: 'wGHE2Pwdvd7S12BL5FaOP20EGYesN73ktiC1qzkkit8=',
})
console.log('Accounts:', result.accounts)
console.log('Genesis Hash:', result.genesisHash)Disconnect
await provider.disconnect()
console.log('Disconnected')Event Handling
Listen for Account Changes
provider.on('accountChanged', (address) => {
if (address) {
console.log('Account changed:', address)
} else {
console.log('Disconnected')
}
})Listen for Connection
provider.on('connect', ({ address }) => {
console.log('Connected:', address)
})
provider.on('disconnect', () => {
console.log('Disconnected')
})Using with Algod Client
Get Client from Provider
// Get pre-configured clients
const algodTransport = await provider.getAlgodv2Client()
const indexerTransport = await provider.getIndexerClient()
// These are BaseHTTPClient transports, not Algodv2 or Indexer SDK instances.
// Use the manual setup below for SDK methods such as status().do().Manual Client Setup
import algosdk from 'algosdk'
const algodClient = new algosdk.Algodv2(
'', // Token (not needed for public nodes)
'https://mainnet-api.algonode.cloud',
''
)
const indexerClient = new algosdk.Indexer(
'',
'https://mainnet-idx.algonode.cloud',
''
)Last updated on