Skip to content

Commit

Permalink
Massive UI work and Readme docs
Browse files Browse the repository at this point in the history
  • Loading branch information
schnetzlerjoe committed Aug 30, 2023
1 parent 78500d8 commit 4007d11
Show file tree
Hide file tree
Showing 34 changed files with 3,158 additions and 6,255 deletions.
232 changes: 216 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,227 @@
# Cosmos Ecosystem MetaMask Snap
# Cosmos MetaMask Snap
Cosmos Metamask Snap aims to add full support of Metamask, a highly popular Ethereum wallet, to all Cosmos SDK blockchains, potentially opening the door to over 30 million Ethereum users and stimulating growth for every project in the Cosmos ecosystem.

Cosmos Ecosystem MetaMask Snap aims to bring the functionalities of MetaMask, a highly popular Ethereum wallet, to the Cosmos network, potentially opening the door to over 20 million Ethereum users and stimulating growth for every project in the Cosmos ecosystem.
## Developer Preview Software
Please note, to develop this Metamask Snap you need to use Metamask Flask, a canary distribution for developers that provides access to upcoming features wihtin Metamask.

## About MetaMask Snaps
## Contribution
Your contributions are always welcome! Please have a look at the [contribution guidelines](CONTRIBUTING.md) first.

MetaMask Snaps is an extensible platform for permissionless innovation that allows developers to extend the functionality of MetaMask with new features and APIs.
## Running Snap
```bash
yarn install
cd packages/snap
yarn start
```

## Key Features of MetaMask Snaps
## Running Snap UI
```bash
yarn install
cd packages/ui
yarn run dev
```

- **Blockchains:** Go beyond Ethereum with snaps for any protocol, including Cosmos.
- **Layer 2s:** Integrate any scaling solution and make exploring Layer 2s accessible to everyone.
- **APIs:** Connect your APIs and services to MetaMask in new and exciting ways.
- **Identity:** Enable authentication, privacy, and consent in ways that keep users in control.
- **Security:** Empower users with more ways to protect their data and employ anti-phishing solutions.
## Install & Initialize
```javascript
// Check if the Snap is installed
await window.ethereum.request({ method: 'wallet_getSnaps' });
const installed = Object.keys(result).includes("npm:@cosmos/snap");

## Security
// Install Snap
if (!installed) {
const result = await window.ethereum.request({
method: 'wallet_requestSnaps',
params: {
'npm:@cosmos/snap': {
version: '^0.1.0',
},
},
});
}

Security is paramount when it comes to MetaMask Snaps. Snaps execute in a sandboxed environment based on Hardened JavaScript (SES) by Agoric. MetaMask Snaps use a permissions model for protecting user data and respecting user consent.
// Initialize the Snap with default chains
await ethereum.request({
method: 'wallet_invokeSnap',
params: {
snapId: 'npm:@cosmos/snap',
request: {
method: 'initialize',
},
},
});
```

## Developer Preview Software
## Check If Initialized
```javascript
// Boolean is returned
const initialized = await ethereum.request({
method: 'wallet_invokeSnap',
params: {
snapId: 'npm:@cosmos/snap',
request: {
method: 'initialized',
},
},
});
```

Please note that MetaMask Snaps is pre-release software. To try out Snaps, you need to install MetaMask Flask, a canary distribution for developers that provides access to upcoming features.
## Suggest Chain
```javascript
// chainInfo should be structured like this https://github.com/cosmos/chain-registry/tree/master/agoric
await window.ethereum.request({
method: 'wallet_invokeSnap',
params: {
snapId: 'npm:@cosmos/snap',
request: {
method: 'addChain',
param: {
chain_info: JSON.stringify(chainInfo),
}
},
},
});
```

## Contribution
## Get Chains
```javascript
const chains = await window.ethereum.request({
method: 'wallet_invokeSnap',
params: {
snapId: 'npm:@cosmos/snap',
request: {
method: 'getChains'
},
},
});
```

Your contributions are always welcome! Please have a look at the [contribution guidelines](CONTRIBUTING.md) first.
## Delete Chain
```javascript
const chain = await window.ethereum.request({
method: 'wallet_invokeSnap',
params: {
snapId: 'npm:@cosmos/snap',
request: {
method: 'deleteChain',
param: {
chain_id: 'cosmoshub-4',
}
},
},
});
```

## Send Transaction
```javascript
const msgs = [
{
typeUrl: "/cosmos.bank.v1beta1.MsgSend",
value: {
fromAddress: senderAddress,
toAddress: recipientAddress,
amount: [{
denom: "uatom",
amount: "500000"
}],
},
}
];
const fees = {
amount: [{
denom: "uatom",
amount: "500"
}],
gas: "200000"
};
const address = await window.ethereum.request({
method: 'wallet_invokeSnap',
params: {
snapId: 'npm:@cosmos/snap',
request: {
method: 'transact',
param: {
chain_id: 'cosmoshub-4',
msgs: JSON.stringify(msgs),
// Optional: Uses default fees for chain if not specified
fees: JSON.stringify(fees)
}
},
},
});
```

## Add Address (Address Book)
```javascript
const address = await window.ethereum.request({
method: 'wallet_invokeSnap',
params: {
snapId: 'npm:@cosmos/snap',
request: {
method: 'addAddress',
param: {
chain_id: 'cosmoshub-4',
address: 'cosmos123456789',
name: 'John Cosmos'
}
},
},
});
```

## Get Addresses (Address Book)
```javascript
const address = await window.ethereum.request({
method: 'wallet_invokeSnap',
params: {
snapId: 'npm:@cosmos/snap',
request: {
method: 'getAddresses'
},
},
});
```

## Delete Address (Address Book)
```javascript
const address = await window.ethereum.request({
method: 'wallet_invokeSnap',
params: {
snapId: 'npm:@cosmos/snap',
request: {
method: 'deleteAddress',
params: {
address: 'cosmos123456789'
}
},
},
});
```

## Get Bech32 Address
```javascript
const address = await window.ethereum.request({
method: 'wallet_invokeSnap',
params: {
snapId: 'npm:@cosmos/snap',
request: {
method: 'getChainAddress',
param: {
chain_id: 'cosmoshub-4',
}
},
},
});
```

## Get Bech32 Addresses
```javascript
const address = await window.ethereum.request({
method: 'wallet_invokeSnap',
params: {
snapId: 'npm:@cosmos/snap',
request: {
method: 'getChainAddresses'
},
},
});
```
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@cosmos/snap",
"version": "0.1.0",
"private": true,
"private": false,
"type": "module",
"description": "The Cosmos extension for your Metamask wallet.",
"homepage": "https://github.com/cosmos/snap#README.md",
Expand Down
Loading

0 comments on commit 4007d11

Please sign in to comment.