Created
January 7, 2024 13:33
-
-
Save jin10086/3bceccd7921947b835bc842c4f761e35 to your computer and use it in GitHub Desktop.
tia_stake.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { readFileSync } from "fs" | |
import { fromHex } from "@cosmjs/encoding" | |
import { DirectSecp256k1Wallet, OfflineDirectSigner } from "@cosmjs/proto-signing" | |
import { SigningStargateClient, StargateClient } from "@cosmjs/stargate" | |
import { MsgSend } from "cosmjs-types/cosmos/bank/v1beta1/tx" | |
import { Tx } from "cosmjs-types/cosmos/tx/v1beta1/tx" | |
const rpc = "https://public-celestia-rpc.numia.xyz" | |
// 其他 rpc https://docs.celestia.org/nodes/mainnet | |
//检查是否质押成功. | |
//https://www.mintscan.io/celestia/address/celestia1yncqx4qq75vqman3clwv97f8tq0ycdh2fcds8e | |
const getAliceSignerFromPriKey = async (pk: string): Promise<OfflineDirectSigner> => { | |
return DirectSecp256k1Wallet.fromKey( | |
fromHex(pk), | |
"celestia" | |
) | |
} | |
function readJsonSync(filePath: string): any { | |
try { | |
const rawData = readFileSync(filePath, 'utf8'); | |
return JSON.parse(rawData); | |
} catch (error) { | |
console.error('Error reading file:', error); | |
return null; | |
} | |
} | |
const dllll = "celestiavaloper1jgqewpzn7dww5tlpnkypm72fm8tjznmw7ll7ls"; | |
const stake = async (signingClient: SigningStargateClient, alice: string, amount: string) => { | |
const result = await signingClient.delegateTokens( | |
alice, | |
dllll, | |
{ denom: "utia", amount: amount }, | |
{ | |
amount: [{ denom: "utia", amount: "30000" }], | |
gas: "300000", | |
}, | |
) | |
console.log("Transfer result:", result) | |
} | |
function sleep(ms: number | undefined) { | |
return new Promise(resolve => setTimeout(resolve, ms)); | |
} | |
function getRandomNumber(min: number, max: number): number { | |
return Math.floor(Math.random() * (max - min + 1)) + min; | |
} | |
const runAll = async (): Promise<void> => { | |
const client = await StargateClient.connect(rpc) | |
// console.log("With client, chain id:", await client.getChainId(), ", height:", await client.getHeight()) | |
const accounts = readJsonSync("accounts.json"); | |
for (const account of accounts) { | |
const aliceSigner: OfflineDirectSigner = await getAliceSignerFromPriKey(account) | |
const alice = (await aliceSigner.getAccounts())[0].address | |
console.log(alice) | |
const randomNumber = getRandomNumber(100000, 110000); | |
// let delega_amount = await client.getDelegation(alice, dllll); | |
// console.log("alice delega ", delega_amount) | |
// await sleep(100); | |
} | |
// const aliceSigner: OfflineDirectSigner = await getAliceSignerFromPriKey() | |
// const alice = (await aliceSigner.getAccounts())[0].address | |
// console.log("Alice's address from signer", alice) | |
// console.log( | |
// "Alice balances:", | |
// await client.getAllBalances(alice) | |
// ) | |
// const signingClient = await SigningStargateClient.connectWithSigner(rpc, aliceSigner) | |
// let delega_amount = await client.getDelegation(alice, dllll); | |
// console.log("alice delega ", delega_amount) | |
} | |
runAll() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment