MyAlgo Connect is a Javascript library developed by Rand Labs to securely sign transactions with My Algo
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
import MyAlgoConnect from '@randlabs/myalgo-connect';
const myAlgoWallet = new MyAlgoConnect();
/*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>
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 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
See LICENSE file.