Skip to content

Commit

Permalink
Doc edits
Browse files Browse the repository at this point in the history
  • Loading branch information
schnetzlerjoe committed Aug 30, 2023
1 parent c0aa347 commit 3feb187
Show file tree
Hide file tree
Showing 4 changed files with 228 additions and 7 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ const initialized = await ethereum.request({
```

## Suggest Chain
This Snap has default support for coin types `118, 564, 60, 459, 529, 330, 494, 639, 483, 4444, 701, 990, 394, 852, 7777777, 880, 931, 371, 370, 505, 234, 5555`. All the coin types within the chain registry. If you need any other please add an issue to the repo [here](https://github.com/cosmos/snap/issues) and we will gladly add it.

Chain info is structured like in the chain registry (i.e [Agoric](https://github.com/cosmos/chain-registry/tree/master/agoric))
```javascript
// chainInfo should be structured like this https://github.com/cosmos/chain-registry/tree/master/agoric
await window.ethereum.request({
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@cosmos/snap",
"name": "@cosmsnap/cosmsnap",
"version": "0.1.0",
"private": false,
"type": "module",
Expand Down
216 changes: 216 additions & 0 deletions packages/snap/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
# 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.

## 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.

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

## 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");

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

// Initialize the Snap with default chains
await ethereum.request({
method: 'wallet_invokeSnap',
params: {
snapId: 'npm:@cosmos/snap',
request: {
method: 'initialize',
},
},
});
```

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

## Suggest Chain
This Snap has default support for coin types `118, 564, 60, 459, 529, 330, 494, 639, 483, 4444, 701, 990, 394, 852, 7777777, 880, 931, 371, 370, 505, 234, 5555`. All the coin types within the chain registry. If you need any other please add an issue to the repo [here](https://github.com/cosmos/snap/issues) and we will gladly add it.

Chain info is structured like in the chain registry (i.e [Agoric](https://github.com/cosmos/chain-registry/tree/master/agoric))
```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),
}
},
},
});
```

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

## 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'
},
},
});
```
14 changes: 8 additions & 6 deletions packages/snap/package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
{
"name": "cosmos-snap",
"version": "0.1.0",
"private": true,
"description": "Cosmos Metamask Snap",
"name": "@cosmsnap/snap",
"version": "0.1.4",
"private": false,
"description": "The Cosmos extension for your Metamask wallet.",
"repository": {
"type": "git",
"url": "https://github.com/cosmos/snap.git"
},
"license": "(MIT-0 OR Apache-2.0)",
"license": "MIT",
"author": "Mystic Labs, Inc",
"main": "src/index.ts",
"files": [
"dist/",
"images/",
"snap.manifest.json"
"snap.manifest.json",
"README.md"
],
"scripts": {
"build": "mm-snap build",
Expand Down

0 comments on commit 3feb187

Please sign in to comment.