Skip to content
This repository has been archived by the owner on Dec 1, 2021. It is now read-only.

Track total number of Cosmos accounts #549

Draft
wants to merge 17 commits into
base: master
Choose a base branch
from
Next Next commit
Initial queryTotalNumberOfAccounts
MonikaCat committed Jun 24, 2021
commit 690e35300ef3a9dd0288406e2c30f09bad36cb10
59 changes: 59 additions & 0 deletions imports/ui/accounts/TotalAccounts.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { getNewWalletFromSeed } from "@lunie/cosmos-keys"
import { signWithPrivateKey } from "@lunie/cosmos-keys"
import Cosmos from "@lunie/cosmos-js"


function getFromAddress(){
const seed = "economy stock theory fatal elder harbor betray wasp final emotion task crumble siren bottom lizard educate guess current outdoor pair theory focus wife stone";
const bech32prefix = 'cosmos';
let hdpath = `m/44'/${COINTYPE}'/0'/0/0`
const { cosmosAddress, privateKey, publicKey } = getNewWalletFromSeed(seed, bech32prefix, hdpath)
return { cosmosAddress, privateKey, publicKey }
}
function getToAddress() {
const seed = "economy stock theory fatal elder harbor betray wasp final emotion task crumble siren bottom lizard educate guess current outdoor pair theory focus wife stone";
const bech32prefix = 'cosmos';
let hdpath = `m/44'/${COINTYPE}'/1'/0/0`
const { cosmosAddress, privateKey, publicKey } = getNewWalletFromSeed(seed, bech32prefix, hdpath)
return { cosmosAddress, privateKey, publicKey }
}
export async function queryTotalNumberOfAccounts(transportBLE, accountIndex) {
// let signMessage = { "account_number": "51442",
// "chain_id": "cosmoshub-4",
// "fee": { "amount": [{ "amount": "1879", "denom": "uatom" }], "gas": "93931" },
// "memo": "Sent via Big Dipper",
// "msgs": [{
// "type": "cosmos-sdk/MsgSend",
// "value": { "amount": [{ "amount": "100000", "denom": "uatom" }],
// "from_address": "cosmos1uulfsj45fvvkr98s859nxkzy08dzejs35ruy3l",
// "to_address": "cosmos1uulfsj45fvvkr98s859nxkzy08dzejs35ruy3l" } }],
// "sequence": "3" }

let getFromAddress = getFromAddress();
let getToAddress = getToAddress();

console.log(getFromAddress, getToAddress);

const cosmos = Cosmos("http://139.162.187.197:1317", getFromAddress.cosmosAddress)
// create message
const msg = cosmos
.MsgSend({ toAddress: getToAddress, amounts: [{ denom: 'uatom', amount: 100 }] })
console.log(msg)
// create a signer from this local js signer library
const localSigner = (signMessage) => {
const signature = signWithPrivateKey(signMessage, privateKey)

return {
signature,
publicKey
}
}

// send the transaction
const { included } = await msg.send({ gas: 200000 }, localSigner)
console.log(included)
// await tx to be included in a block
await included()

return ''
}
473 changes: 473 additions & 0 deletions package-lock.json
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -11,8 +11,13 @@
},
"dependencies": {
"@babel/runtime": "^7.13.17",
"@cosmjs/amino": "^0.25.5",
"@cosmjs/proto-signing": "^0.25.5",
"@cosmjs/stargate": "^0.25.5",
"@ledgerhq/hw-transport-web-ble": "^5.50.0",
"@ledgerhq/hw-transport-webusb": "^5.53.0",
"@lunie/cosmos-js": "0.0.22",
"@lunie/cosmos-keys": "^0.3.2",
"@types/meteor-universe-i18n": "^1.14.5",
"axios": "^0.21.1",
"babel-polyfill": "^6.26.0",