Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
grikomsn committed Sep 1, 2023
0 parents commit de5ce0d
Show file tree
Hide file tree
Showing 11 changed files with 3,598 additions and 0 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
MNEMONIC="lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua ut enim ad minim veniam"
7 changes: 7 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// @ts-check

const { extendEslint } = require("@graz-sh/style-guide-core");

module.exports = extendEslint(["node", "typescript"], {
root: true,
});
16 changes: 16 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# default ignored directores/files
**/node_modules/
*.log
.DS_Store
.env*
.eslintcache
.turbo
.vercel
dist/**
package-lock.json
tsconfig.tsbuildinfo
vendor/**

# allowed directories/files
!.gitkeep
!.env.example
2 changes: 2 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
public-hoist-pattern[]=*
# enable-pre-post-scripts=true
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
18
19 changes: 19 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"[stubs/*.ts]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[javascript]": {
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
},
"[javascriptreact]": {
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
},
"[typescript]": {
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
},
"[typescriptreact]": {
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
},
"eslint.validate": ["javascript", "javascriptreact", "typescript", "typescriptreact"],
"npm.packageManager": "pnpm"
}
5 changes: 5 additions & 0 deletions env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare namespace NodeJS {
interface ProcessEnv {
readonly MNEMONIC?: string;
}
}
52 changes: 52 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import type { EncodeObject } from "@cosmjs/proto-signing";
import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
import { GasPrice, SigningStargateClient } from "@cosmjs/stargate";
import { MsgSend } from "cosmjs-types/cosmos/bank/v1beta1/tx";

const addresses = {
griko_nibras: `cosmos1kpzxx2lxg05xxn8mfygrerhmkj0ypn8edmu2pu`,
kikiding: `cosmos1g3jjhgkyf36pjhe7u5cw8j9u6cgl8x929ej430`,
asaadam: `cosmos1q7u2wv5rmzphm53cww42ydcrsgjp7he8u3f85f`,
};

const run = async () => {
// https://github.com/cosmos/chain-registry/blob/master/cosmoshub/chain.json
const chainId = "cosmoshub-4";
const rpcEndpoint = "https://rpc.cosmos.directory/cosmoshub";
const bech32Prefix = "cosmos";

const mnemonic = process.env.MNEMONIC || raise("configure mnemonic in .env file");
const offlineSigner = await DirectSecp256k1HdWallet.fromMnemonic(mnemonic, { prefix: bech32Prefix });

const accounts = await offlineSigner.getAccounts();
const account = accounts[0] || raise("no account found");

const signingClient = await SigningStargateClient.connectWithSigner(rpcEndpoint, offlineSigner, {
gasPrice: GasPrice.fromString("0.025uatom"),
});

const sendTokenPayload = MsgSend.fromPartial({
fromAddress: account.address,
toAddress: addresses.griko_nibras,
amount: [{ amount: "10000", denom: "uatom" }],
});

const encodedSendTokenPayload = MsgSend.encode(sendTokenPayload).finish();

const messagesToSend: EncodeObject[] = [
{
typeUrl: "/cosmos.bank.v1beta1.MsgSend",
value: encodedSendTokenPayload,
},
];

const response = await signingClient.signAndBroadcast(account.address, messagesToSend, "auto");

console.log(response);
};

const raise = (message?: string): never => {
throw new Error(message);
};

void run();
17 changes: 17 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"scripts": {
"start": "tsx -r dotenv/config index.ts"
},
"dependencies": {
"@cosmjs/proto-signing": "^0.31.1",
"@cosmjs/stargate": "^0.31.1",
"@graz-sh/style-guide-core": "^4.0.1",
"@types/node": "^18.17.12",
"cosmjs-types": "^0.8.0",
"eslint": "^8.48.0",
"prettier": "^3.0.3",
"tsx": "^3.12.8"
},
"prettier": "@graz-sh/style-guide-core/prettier",
"private": true
}
Loading

0 comments on commit de5ce0d

Please sign in to comment.