/myalgo-connect

Browser package to bring access to MyAlgo Wallet accounts to dApps

Primary LanguageJavaScriptApache License 2.0Apache-2.0

MyAlgo Connect

npm version Website shields.io Discord Twitter

myalgo-logo

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.