1.0.2 • Published 2 years ago

hotwallet-api v1.0.2

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
2 years ago

hotwallet-api

A JavaScript/TypeScript browser api for interacting with Hotwallet, the wallet browser extension of Hotmoka blockchain. This library gets injected by the Hotwallet browser extension into the current document.

Usage

import { isExtensionAvailable, StorageValueFactory } from 'hotwallet-api'

// check if Hotwallet extension is available 
isExtensionAvailable().then(isAvailable => {
    
    if (isAvailable) {
        // access hotwalletApi instance of window object
        // try to connect to Hotwallet
        window.hotwalletApi.connect().then(account => {
            alert('Connected successfully Hotwallet')
        })
        .catch(err => alert(err.message))
    } else {
        alert('Hotwallet extension not installed')
    }
})
.catch(() => alert('Hotwallet extension not installed'))

// send transaction
window.hotwalletApi.sendTransaction({
    smartContractAddress: {
        type: 'local',
        hash: '...'
    },
    methodSignature: {
        instanceMethod: true,
        voidMethod: true,
        definingClass: 'HelloWorld',
        methodName: 'testMe',
        formals: ['java.math.BigInteger', 'java.lang.String']
    },
    receiver: {
        type: 'local',
        hash: '...'
    },
    actuals: [
        StorageValueFactory.newStorageValue('20000', 'java.math.BigInteger'),
        StorageValueFactory.newStorageValue('hello world', 'java.lang.String'),
    ],
    amount: '5000',
    name: 'Transaction test'
})
.then(result => ...)
.catch(err => ...)

Build

Requirements

Install dependencies

npm install

Bundle source code

npm run bundle

Tests

npm run test:all