algorand on metamask
npm install algorandjavascript
async function connect () {
await window.ethereum.request({
method: 'wallet_enable',
params: [{
wallet_snap: { 'npm:algorand': {} },
}]
})
}
`
$3
Below is an example call to the snap that transacts 1000 microalgos to an entered public address. Again this can be run with 0 dependency other than metamask flask
---
All methods can be called with the param:
testnet: (bool)
if the method does not depend on the testnet it is ignored
if the method can be used with testnet, testnet is then used instead
---
`javascript
const address = prompt("Please enter your recipient Address");
const response = await window.ethereum.request({
method: 'wallet_invokeSnap',
params: ['npm:algorand', {
method: 'transfer',
params:{
testnet: false,
to: address,
amount: 1000
}
}]
})
`
$3
---
Account functions
These functions handle getting infomation about a users account, assets, balance, and history
---
#### displayBalance
Displays the users current balance in a metamask flask popup
`javascript
await window.ethereum.request({
method: 'wallet_invokeSnap',
params:['npm:algorand',{
method: 'displayBalance',
params:{
testnet: false
}
}]
})
`
#### getBalance
returns the users current balance
`javascript
await window.ethereum.request({
method: 'wallet_invokeSnap',
params: ['npm:algorand', {
method: 'getBalance',
parms:{
testnet: false
}
}]
})
`
#### getAddress
returns the public address of the wallet
`javascript
let address = await window.ethereum.request({
method: 'wallet_invokeSnap',
params: ['npm:algorand', {
method: 'getAddress',
}]
})
`
#### transfer
transfers a number of algos to a specified address
`javascript
const address = prompt("Please enter your name");
const response = await window.ethereum.request({
method: 'wallet_invokeSnap',
params: ['npm:algorand', {
method: 'transfer',
params:{
testnet: false,
to: address,
amount: 1000
?note: "string"
}
}]
})
`
#### displayMnemonic
displays the wallets algorand mnemonic in a secure metamask window
`javascript
await window.ethereum.request({
method: 'wallet_invokeSnap',
params: ['npm:algorand', {
method: 'displayMnemonic'
}]
})
`
#### getTransactions
returns a list of javascript objects containing transaction data
`javascript
await window.ethereum.request({
method: 'wallet_invokeSnap',
params: ['npm:algorand', {
method: 'getTransactions',
params:{
testnet: false
}
}]
})
`
$3
returns a list of the current accounts assets
`javascript
await window.ethereum.request({
method: 'wallet_invokeSnap',
params: ['npm:algorand', {
method: 'getAssets',
params:{
testnet: false
}
}]
})
`
$3
returns an object containing all of the algorand accounts on a users metamask
`javascript
await window.ethereum.request({
method: 'wallet_invokeSnap',
params: ['npm:algorand', {
method: 'getAccounts',
}]
})
`
$3
returns the users current Account
`javascript
returns the users current Account
await window.ethereum.request({
method: 'wallet_invokeSnap',
params: ['npm:algorand', {
method: 'getCurrentAccount',
}]
})
`
$3
sets the Users Current Account
takes an algorand address as a parameter and throws an error if the address is not contained in the users wallet
returns the users current Account
`javascript
await window.ethereum.request({
method: 'wallet_invokeSnap',
params: ['npm:algorand', {
method: 'setCurrentAccount',
}]
})
`
*
Arc Complience Functions
these functions are used ARC complient ways to sign arbitray transactions
*
$3
sign an array of WalletTransaction objects
returns an array of signed b64 algorand transactions
`javascript
await window.ethereum.request({
method: 'wallet_invokeSnap',
params: ['npm:algorand', {
method: 'signTxns'
params:{
txns:[WalletTransaction]
}
}]
})
`
$3
takes an array of b64 signed algorand transactions. Like the output of signTxns and sends them to the algorand blockchain.
`javascript
await window.ethereum.request({
method: 'wallet_invokeSnap',
params: ['npm:algorand', {
method: 'postTxns'
params:{
stxns: ["b64SignedTxn"]
}
}]
})
`
$3
takes an array of WalletTransaction objects and signs then posts them to the algorand blockchain
`javascript
await window.ethereum.request({
method: 'wallet_invokeSnap',
params: ['npm:algorand', {
method: 'signAndPostTxns'
params:{
txns: [WalletTransaction]
}
}]
})
`
*
Asset Functions
the functions are used to interact with algorand assets
*
$3
opts into an algorand asset
`javascript
await window.ethereum.request({
method: 'wallet_invokeSnap',
params: ['npm:algorand', {
method: 'assetOptIn'
params:{
assetIndex: int
}
}]
})
`
$3
opts out of an algorand asset
`javascript
await window.ethereum.request({
method: 'wallet_invokeSnap',
params: ['npm:algorand', {
method: 'assetOptOut'
params:{
assetIndex: int
}
}]
})
`
$3
sends an algorand asset to another wallet that is opted into the given asset
`javascript
await window.ethereum.request({
method: 'wallet_invokeSnap',
params: ['npm:algorand', {
method: 'assetOptOut'
params:{
assetIndex: int
to: "algorandAddress"
amount: string
}
}]
})
`
*
swapping functions
These functions are used to swap crypto between
Algorand, Etherum, and Binance Smart Chain
The ticker values are
algo | eth | bsc
*
$3
get minimum input amount for a specific swap
`javascript
async function getMin(){
const result = await ethereum.request({
method: 'wallet_invokeSnap',
params: [
'npm:algorand', {
method: 'getMin',
params:{
from: 'eth' | 'bsc' | 'algo',
to: 'eth' | 'bsc' | 'algo',
}
}
]
})
return result;
}
`
$3
Get infomation about a swap without actually swapping
`javascript
async function preSwap(){
const result = await ethereum.request({
method: 'wallet_invokeSnap',
params: [
'npm:algorand', {
method: 'preSwap',
params:{
from: 'eth' | 'bsc' | 'algo',
to: 'eth' | 'bsc' | 'algo',
amount: Number(amount) //done in base units i.e. eth not wei
}
}
]
})
return result
}
`
$3
swap currencies
this will automatically send send the required currency to the exchange and use the selected address to receive the cash
uses changenow
`javascript
async function swap(){
const result = await ethereum.request({
method: 'wallet_invokeSnap',
params: [
'npm:algorand', {
method: 'swap',
params:{
from: 'eth' | 'bsc' | 'algo',
to: 'eth' | 'bsc' | 'algo',
amount: Number(amount) //done in base units i.e. eth not wei
email: String("emailAddress@example.com") //completely optional
}
}
]
})
return result
}
`
$3
the method returns an array of swap objects that give info about a swap performed by a given wallet.
`javascript
async function swapHistory(){
const result = await ethereum.request({
method: 'wallet_invokeSnap',
params: [
'npm:algorand', {
method: 'swapHistory',
}
]
})
return result
}
`
$3
this method returns a status object of swap given the swaps id that can be obtained from swap history
`javascript
async function swapHistory(){
const result = await ethereum.request({
method: 'wallet_invokeSnap',
params: [
'npm:algorand', {
method: 'getSwapStatus',
params:{
id: 'changenowSwapID'
}
}
]
})
return result
}
``