10.0.0 • Published 12 months ago

algorand v10.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

SNAPALGO

ALGORAND on MetaMask

SnapAlgo is an Algorand wallet built on metamask developmental snaps feature which allows code to be run in a secure execution enviroment inside the metamask extension itself. Because the feature is so new it is currently only available on Metamask Flask which can be found here https://metamask.io/flask/

Demo

snapalgo.io

example apps

simple wallet

https://snapalgowallet.netlify.app/

Simple Swap app

https://algoswap.netlify.app/

Useage

building

npx mm-snap build

compiles the src folder into a functional version of the snap

serving

npx mm-snap serve

Serves index.html on port 3000

sdk

It is possible to use an sdk to simplify using snapalgo. repository This creates a floating wallet on the dapp for better user experence. As well as creating an easier developer experence by not requiring the developer to call raw rpc functions.

Connect and Install

Add and Call the below function to connect to the wallet. If the user does not have the snap installed, but has metamask flask installed this code will automaticly install it for them. This code snippet can be added to any website with 0 depenancies otheer than metamask flask

async  function  connect () {
	await window.ethereum.request({
		method:  'wallet_enable',
		params: [{
			wallet_snap: { 'npm:algorand': {} },
		}]
	})
}

Calling RPC Methods

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

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
		}
	}]
})

Available RPC Methods


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

await window.ethereum.request({
	method: 'wallet_invokeSnap',
	params:['npm:algorand',{
		method: 'displayBalance',
		params:{
			testnet: false
		}
	}]
})

getBalance

returns the users current balance

await window.ethereum.request({
	method:  'wallet_invokeSnap',
	params: ['npm:algorand', {
		method:  'getBalance',
		parms:{
			testnet:  false
		}
	}]
})

getAddress

returns the public address of the wallet

let address = await window.ethereum.request({
	method:  'wallet_invokeSnap',
	params: ['npm:algorand', {
		method:  'getAddress',
	}]
})

transfer

transfers a number of algos to a specified address

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

await window.ethereum.request({
	method:  'wallet_invokeSnap',
	params: ['npm:algorand', {
		method:  'displayMnemonic'
	}]
})

getTransactions

returns a list of javascript objects containing transaction data

await window.ethereum.request({
	method: 'wallet_invokeSnap',
	params: ['npm:algorand', {
		method: 'getTransactions',
		params:{
			testnet: false
		}
	}]
})

getAssets

returns a list of the current accounts assets

await window.ethereum.request({
	method: 'wallet_invokeSnap',
	params: ['npm:algorand', {
		method: 'getAssets',
		params:{
			testnet: false
		}
	}]
})

get Accounts

returns an object containing all of the algorand accounts on a users metamask

await window.ethereum.request({
	method: 'wallet_invokeSnap',
	params: ['npm:algorand', {
		method: 'getAccounts',
	}]
})

get Current Account

returns the users current Account

returns the users current Account
await window.ethereum.request({
	method: 'wallet_invokeSnap',
	params: ['npm:algorand', {
		method: 'getCurrentAccount',
	}]
})

set Current Account

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

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


signTxns

sign an array of WalletTransaction objects returns an array of signed b64 algorand transactions

await window.ethereum.request({
	method: 'wallet_invokeSnap',
	params: ['npm:algorand', {
		method: 'signTxns'
		params:{
			txns:[WalletTransaction]
		}
	}]
})

postTxns

takes an array of b64 signed algorand transactions. Like the output of signTxns and sends them to the algorand blockchain.

await window.ethereum.request({
	method: 'wallet_invokeSnap',
	params: ['npm:algorand', {
		method: 'postTxns'
		params:{
			stxns: ["b64SignedTxn"]
		}
	}]
})

signAndPostTxns

takes an array of WalletTransaction objects and signs then posts them to the algorand blockchain

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


assetOptIn

opts into an algorand asset

await window.ethereum.request({
	method: 'wallet_invokeSnap',
	params: ['npm:algorand', {
		method: 'assetOptIn'
		params:{
			assetIndex: int
		}
	}]
})

assetOptOut

opts out of an algorand asset

await window.ethereum.request({
	method: 'wallet_invokeSnap',
	params: ['npm:algorand', {
		method: 'assetOptOut'
		params:{
			assetIndex: int
		}
	}]
})

transferAsset

sends an algorand asset to another wallet that is opted into the given asset

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


get Minimum

get minimum input amount for a specific swap

    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;
    }

preSwap

Get infomation about a swap without actually swapping

	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
	}

swap

swap currencies this will automatically send send the required currency to the exchange and use the selected address to receive the cash uses changenow

	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
	}

swapHistory

the method returns an array of swap objects that give info about a swap performed by a given wallet.

	async function swapHistory(){
		const result = await ethereum.request({
			method: 'wallet_invokeSnap',
			params: [
			'npm:algorand', {
				method: 'swapHistory',
			}
			]
		})
		return result
	}

getSwapStatus

this method returns a status object of swap given the swaps id that can be obtained from swap history

	async function swapHistory(){
		const result = await ethereum.request({
			method: 'wallet_invokeSnap',
			params: [
			'npm:algorand', {
				method: 'getSwapStatus',
				params:{
					id: 'changenowSwapID'
				}
			}
			]
		})
		return result
	}

More RPC methods to come

10.0.0

12 months ago

8.1.0

12 months ago

8.0.9

12 months ago

8.0.5

12 months ago

8.0.4

12 months ago

8.0.7

12 months ago

8.0.6

12 months ago

8.0.1

12 months ago

8.0.3

12 months ago

8.0.2

12 months ago

8.0.0

1 year ago

7.0.0

1 year ago

7.0.1

1 year ago

5.3.0

1 year ago

5.4.0

1 year ago

5.5.1

1 year ago

5.5.0

1 year ago

6.0.1

1 year ago

6.0.0

1 year ago

6.0.2

1 year ago

5.2.3

1 year ago

5.2.2

1 year ago

5.2.0

2 years ago

5.1.0

2 years ago

5.0.4

2 years ago

5.0.3

2 years ago

5.0.2

2 years ago

5.0.1

2 years ago

5.0.0

2 years ago

4.0.25

2 years ago

4.0.23

2 years ago

4.0.21

2 years ago

4.0.20

2 years ago

4.0.19

2 years ago

4.0.18

2 years ago

4.0.17

2 years ago

4.0.16

2 years ago

4.0.15

2 years ago

4.0.14

2 years ago

4.0.13

2 years ago

4.0.12

2 years ago

4.0.11

2 years ago

4.0.10

2 years ago

4.0.9

2 years ago

4.0.8

2 years ago

4.0.7

2 years ago

4.0.6

2 years ago

4.0.5

2 years ago

4.0.4

2 years ago

4.0.3

2 years ago

4.0.2

2 years ago

4.0.1

2 years ago

4.0.0

2 years ago

3.2.39

2 years ago

3.2.38

2 years ago

3.2.37

2 years ago

3.2.36

2 years ago

3.2.35

2 years ago

3.2.33

2 years ago

3.2.32

2 years ago

3.2.31

2 years ago

3.2.30

2 years ago

3.2.29

2 years ago

3.2.28

2 years ago

3.2.27

2 years ago

3.2.26

2 years ago

3.2.25

2 years ago

3.2.24

2 years ago

3.2.23

2 years ago

3.2.22

2 years ago

3.2.21

2 years ago

3.2.19

2 years ago

3.2.18

2 years ago

3.2.17

2 years ago

3.2.16

2 years ago

3.2.15

2 years ago

3.2.14

2 years ago

3.2.13

2 years ago

3.2.12

2 years ago

3.2.11

2 years ago

3.2.10

2 years ago

3.2.9

2 years ago

3.2.8

2 years ago

3.2.7

2 years ago

3.2.6

2 years ago

3.2.5

2 years ago

3.2.4

2 years ago

3.2.3

2 years ago

3.2.2

2 years ago

3.2.1

2 years ago

3.2.0

2 years ago

3.1.1

2 years ago

3.1.0

2 years ago

3.0.22

2 years ago

3.0.21

2 years ago

3.0.20

2 years ago

3.0.19

2 years ago

3.0.18

2 years ago

3.0.17

2 years ago

3.0.16

2 years ago

3.0.15

2 years ago

3.0.14

2 years ago

3.0.13

2 years ago

3.0.12

2 years ago

3.0.11

2 years ago

3.0.10

2 years ago

3.0.9

2 years ago

3.0.8

2 years ago

3.0.7

2 years ago

3.0.6

2 years ago

3.0.5

2 years ago

3.0.4

2 years ago

3.0.3

2 years ago

3.0.2

2 years ago

3.0.1

2 years ago

3.0.0

2 years ago

2.0.9

2 years ago

2.0.8

2 years ago

2.0.7

2 years ago

2.0.6

2 years ago

2.0.5

2 years ago

2.0.4

2 years ago

2.0.3

2 years ago

2.0.2

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.1.7

2 years ago

1.1.6

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago