Skip to main content

Get Started

Aioha core may be installed through npm or imported through CDN using ES6 module import syntax.

NPM Installation

npm i @aioha/aioha

CDN Import

index.html
<script type="module">
import { initAioha } from 'https://unpkg.com/@aioha/aioha@latest/dist/bundle.js'
</script>

Usage Example

Instantiating Aioha, logging in and transacting on Hive can be done with just one or two lines of code for each task. Most configuration are provider-specific.

import { initAioha, Asset, KeyTypes, Providers } from '@aioha/aioha'

// Instantiation
const aioha = initAioha({
hiveauth: {
name: 'Aioha',
description: 'Aioha test app'
},
hivesigner: {
app: 'ipfsuploader.app',
callbackURL: window.location.origin + '/hivesigner.html',
scope: ['login', 'vote']
}
})

// Get registered providers
console.log(aioha.getProviders())

// Get current logged in user and provider name
if (aioha.isLoggedIn()) {
console.log(aioha.getCurrentUser(), aioha.getCurrentProvider())
}

// Login with provider
const login = await aioha.login(Providers.Keychain, 'hiveusername', {
msg: 'Hello World',
keyType: KeyTypes.Posting,
hiveauth: {
cbWait: (payload, evt) => {
// display HiveAuth QR code using `payload` as data
}
}
})

// Transfer 1 HIVE using logged in provider
const xfer = await aioha.transfer('recipient', 1, Asset.HIVE, 'Transferred using Aioha with memo')

// Vote comment with 100% weight
const vote = await aioha.vote('author', 'permlink', 10000)

// Claim rewards
const rewardClaim = await aioha.claimRewards()

HiveSigner Callback Page

HiveSigner provider requires a callback page that stores the login and transaction results into localStorage which is then used as callback data for the application. The function is included in src/lib/hivesigner-cb.ts file in Aioha core and may be used as such:

<script type="module">
import { hivesignerCb } from 'https://unpkg.com/@aioha/aioha@latest/dist/hivesigner-cb.js'
hivesignerCb()
</script>

Polyfills

When using Aioha with bundlers such as Webpack or Vite, you may need to add some polyfills for it to work correctly.

webpack.config.cjs
const { DefinePlugin, ProvidePlugin } = require('webpack')

module.exports = {
// ...
resolve: {
// ...
fallback: {
url: false,
buffer: require.resolve('buffer/')
}
},
plugins: [
// ...
new DefinePlugin({
'process.env.NODE_DEBUG': false
}),
new ProvidePlugin({
Buffer: ['buffer', 'Buffer']
})
]
}

Chunking

To keep the main bundle as lightweight as possible, enable chunking (or code splitting) in your bundler.

webpack.config.cjs
module.exports = {
// ...
optimization: {
splitChunks: {
name: (module, chunks, cacheGroupKey) => {
const allChunksNames = chunks.map((chunk) => chunk.name).join('-')
return allChunksNames
}
}
}
}