├── .env.example ├── .gitignore ├── README.md ├── index.js ├── package.json ├── transfer.js └── wallet_gen.js /.env.example: -------------------------------------------------------------------------------- 1 | NODE_URL=public-celestia-consensus.numia.xyz:26657 2 | PRIVATE_KEY= -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | .env 3 | node_modules 4 | yarn.lock 5 | yarn-error.log 6 | celestia_wallets.json -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # cias 批量自转脚本 2 | 3 | ## 助记词转私钥 4 | 把你的助记词导入小青蛙钱包(leap wallet),然后导出私钥,然后私钥导入keplr钱包,然后就能在keplr看到你的私钥了 5 | leap显示的私钥和keplr的不一样 6 | 7 | ## 安装 8 | ### 安装 nodejs 9 | 10 | https://nodejs.org/en/download/ 11 | 12 | ### 安装 yarn 13 | 先进入到根目录再执行 14 | ``` 15 | npm install -g yarn 16 | ``` 17 | ``` 18 | yarn install 19 | ``` 20 | 21 | ## 配置环境变量 22 | 修改 .env.example 为 .env,并填写以下信息: 23 | 24 | RPC在这文档里找,记得把端口加上: https://docs.celestia.org/nodes/mainnet 25 | ``` 26 | NODE_URL= 27 | PRIVATE_KEY= 28 | ``` 29 | 30 | ## 钱包批量生成 31 | ``` 32 | node wallet_gen.js 33 | ``` 34 | 35 | 代码里面可以调整生成的个数,执行后会生成一个 celestia_wallets.json 文件 36 | 37 | ## 批量转账 38 | 39 | ``` 40 | node transfer.js 41 | ``` 42 | 请先执行批量生成,然后再执行批量转账 43 | 默认给生成的 celestia_wallets.json 里面所有的地址转 1 个 TIA ,请按需调整 44 | 45 | ## 批量mint 46 | 用 celestia_wallets.json 里的所有地址来 mint,没有的话按相同格式自行添加 47 | ``` 48 | node index.js 49 | ``` 50 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | require('dotenv').config(); 2 | const { SigningStargateClient, GasPrice, coins } = require("@cosmjs/stargate"); 3 | const { DirectSecp256k1Wallet } = require('@cosmjs/proto-signing'); 4 | const { readFileSync } = require("fs"); 5 | const {base64FromBytes} = require("cosmjs-types/helpers"); 6 | 7 | async function performTransaction(walletInfo, numberOfTimes) { 8 | const rpcEndpoint = process.env.NODE_URL; 9 | const gasPrice = GasPrice.fromString("0.025utia"); 10 | const wallet = await DirectSecp256k1Wallet.fromKey(Buffer.from(walletInfo.privateKey, "hex"), "celestia"); 11 | const client = await SigningStargateClient.connectWithSigner(rpcEndpoint, wallet, { gasPrice: gasPrice }); 12 | const fee = { 13 | amount: coins(400, "utia"), 14 | gas: "80000", 15 | }; 16 | for (let i = 0; i < numberOfTimes; i++) { 17 | try { 18 | const [account] = await wallet.getAccounts(); 19 | const amount = coins(1, "utia"); 20 | const memo = 'data:,{"op":"mint","amt":10000,"tick":"cias","p":"cia-20"}'; 21 | const result = await client.sendTokens(account.address, account.address, amount, fee, base64FromBytes(Buffer.from(memo, 'utf8'))); 22 | if(result.code === 0) { 23 | console.log(`${account.address}, 第 ${i + 1} 次操作成功: ${'https://www.mintscan.io/celestia/tx/' + result.transactionHash}`); 24 | } else { 25 | console.log(`${account.address}, 第 ${i + 1} 次操作失败: ${'https://www.mintscan.io/celestia/tx/' + result.transactionHash}`); 26 | } 27 | } catch (error) { 28 | console.error(`第 ${i + 1} 次操作失败: `, error); 29 | } 30 | } 31 | } 32 | 33 | async function main() { 34 | let walletData = []; 35 | try { 36 | walletData = JSON.parse(readFileSync('celestia_wallets.json', 'utf-8')); 37 | } catch (e) { 38 | console.log('未找到 celestia_wallets.json,使用配置的主钱包'); 39 | } 40 | //const privateKey = process.env.PRIVATE_KEY; 41 | //const wallet = await DirectSecp256k1Wallet.fromKey(Buffer.from(privateKey, "hex"), "cosmos"); 42 | //const [account] = await wallet.getAccounts(); 43 | //const walletAddress = account.address; 44 | 45 | //const client = await SigningStargateClient.connectWithSigner(process.env.NODE_URL, wallet); 46 | //const balance = await client.getBalance(walletAddress, "uatom"); 47 | //console.log(`地址: ${walletAddress} 余额: ${parseFloat(balance.amount) / 1000000}`); 48 | //walletData.push( { 49 | // "address": walletAddress, 50 | // "privateKey": privateKey 51 | //}); 52 | Promise.all(walletData.map(wallet => performTransaction(wallet, 10000))) 53 | .then(() => { 54 | console.log("所有操作完成"); 55 | }) 56 | .catch(error => { 57 | console.error("操作中有错误发生: ", error); 58 | }); 59 | } 60 | 61 | main(); 62 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "coss", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "license": "MIT", 6 | "dependencies": { 7 | "@cosmjs/crypto": "^0.32.0", 8 | "@cosmjs/proto-signing": "^0.32.0", 9 | "@cosmjs/stargate": "^0.32.0", 10 | "bip39": "^3.1.0", 11 | "cosmjs-types": "^0.9.0", 12 | "cosmos-lib": "^1.1.0", 13 | "dotenv": "^16.3.1", 14 | "fs": "^0.0.1-security" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /transfer.js: -------------------------------------------------------------------------------- 1 | require('dotenv').config(); 2 | const { SigningStargateClient, GasPrice, coins } = require("@cosmjs/stargate"); 3 | const { DirectSecp256k1Wallet } = require('@cosmjs/proto-signing'); 4 | const {readFileSync} = require("fs"); 5 | 6 | async function main() { 7 | const rpcEndpoint = process.env.NODE_URL; 8 | const privateKey = process.env.PRIVATE_KEY; //主账户私钥 9 | const wallet = await DirectSecp256k1Wallet.fromKey(Buffer.from(privateKey, "hex"), "celestia"); 10 | const [account] = await wallet.getAccounts(); 11 | const gasPrice = GasPrice.fromString("0.025utia"); 12 | const client = await SigningStargateClient.connectWithSigner(rpcEndpoint, wallet, { gasPrice: gasPrice }); 13 | const balance = await client.getBalance(account.address, "utia"); 14 | console.log(`主账户地址: ${account.address} 余额: ${parseFloat(balance.amount) / 1000000}`); 15 | const wallets = JSON.parse(readFileSync('celestia_wallets.json', 'utf-8')); 16 | const recipients = wallets.map(wallet => wallet.address); 17 | 18 | // 1 tia 等于 1000000 utia 19 | const amount = coins(1000000, "utia"); 20 | for (const recipient of recipients) { 21 | try { 22 | const fee = { 23 | amount: coins(400, "utia"), 24 | gas: "100000", 25 | }; 26 | const result = await client.sendTokens(account.address, recipient, amount, fee); 27 | if(result.code === 0) { 28 | console.log(`${recipient}: 转账 ${amount.toString()} 成功: ${'https://www.mintscan.io/celestia/tx/' + result.transactionHash}`); 29 | } else { 30 | console.log(`${recipient}: 转账 ${amount.toString()} 失败: ${'https://www.mintscan.io/celestia/tx/' + result.transactionHash}`); 31 | } 32 | } catch (error) { 33 | console.error(`转账给 ${recipient} 失败: `, error); 34 | } 35 | } 36 | } 37 | 38 | main(); 39 | -------------------------------------------------------------------------------- /wallet_gen.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs'); 2 | const bip39 = require("bip39"); 3 | const { crypto } = require("cosmos-lib"); 4 | const {DirectSecp256k1Wallet} = require("@cosmjs/proto-signing"); 5 | 6 | async function generateCosmosWallets(numberOfWallets) { 7 | let walletData = []; 8 | 9 | for (let i = 0; i < numberOfWallets; i++) { 10 | const mnemonic = bip39.generateMnemonic(); 11 | const keys = crypto.getKeysFromMnemonic(mnemonic); 12 | const wallet = await DirectSecp256k1Wallet.fromKey(Buffer.from(keys.privateKey), "celestia"); 13 | const [account] = await wallet.getAccounts(); 14 | const walletAddress = account.address; 15 | walletData.push({ 16 | address: walletAddress, 17 | mnemonic: mnemonic, 18 | privateKey: keys.privateKey.toString('hex') 19 | }); 20 | } 21 | 22 | fs.writeFileSync('celestia_wallets.json', JSON.stringify(walletData, null, 4)); 23 | } 24 | 25 | generateCosmosWallets(100).then(() => { 26 | console.log("Wallets generated and saved to celestia_wallets.json"); 27 | }); 28 | --------------------------------------------------------------------------------