@randlabs/myalgo-connect
v1.4.2
Published
[![npm version](https://badge.fury.io/js/@randlabs%2Fmyalgo-connect.svg)](https://badge.fury.io/js/@randlabs%2Fmyalgo-connect) [![Website shields.io](https://img.shields.io/website-up-down-green-red/http/shields.io.svg)](https://connect.myalgo.com/) [![Di
Downloads
204,183
Readme
MyAlgo Connect
Overview
MyAlgo Connect is a Javascript library developed by Rand Labs to securely sign transactions with My Algo
Installation
The package can be installed via npm:
npm i @randlabs/myalgo-connect
or imported in the HTML
<script src="./myalgo.min.js"></script>
Find the browser minified version in our github releases
API Usage
Quick start
import MyAlgoConnect from '@randlabs/myalgo-connect';
const myAlgoWallet = new MyAlgoConnect();
Connect to My Algo
/*Warning: Browser will block pop-up if user doesn't trigger myAlgoWallet.connect() with a button interation */
async function connectToMyAlgo() {
try {
const accounts = await myAlgoWallet.connect();
const addresses = accounts.map(account => account.address);
} catch (err) {
console.error(err);
}
}
<button onclick="connectToMyAlgo()">Connect!</button>
Sign transaction
import algosdk from 'algosdk';
const algodClient = new algosdk.Algodv2('', 'https://node.algoexplorerapi.io/', 443);
/*Warning: Browser will block pop-up if user doesn't trigger myAlgoWallet.connect() with a button interation */
async function signTransaction (from, to, amount, suggestedParams) {
try {
const txn = algosdk.makePaymentTxnWithSuggestedParams({ suggestedParams, from, to, amount });
const signedTxn = await myAlgoWallet.signTransaction(txn.toByte());
const response = await algodClient.sendRawTransaction(signedTxn.blob).do();
console.log(response)
} catch(err) {
console.error(err);
}
};
Documentation
Documentation for this package is available here: https://connect.myalgo.com/. An example of an integration with MyAlgo Connect: https://github.com/randlabs/myalgo-connect-test
Copyright and License
See LICENSE file.