Skip to main content

Thử nghiệm Mạng Cosmos Phần

CosmJS

Để sử dụng chức năng thư viện cosmJS trong mạng CrossFi, bạn cần vá thư viện cosmJS như trong ví dụ: https://github.com/crossfichain/js-tx-example

const  = require('@cosmjs/crypto');
const = require('@cosmjs/proto-signing');
const = require('@cosmjs/stargate');
const bech32Converter = require('bech32-converting');

require('dotenv').config();

const COSMOS_RPC_URL = 'https://tendermint-rpc.testnet.ms/';
const MNEMONIC = process.env.MNEMONIC || '';
const GAS_PRICE = ;
const PREFIX = 'mx';
const HD_PATHS = [stringToPath("m/44'/118'/0'/0/0"), stringToPath("m/44'/60'/0'/0/0")];

async function main() ;
const signer = await DirectSecp256k1HdWallet.fromMnemonic(MNEMONIC, { prefix: PREFIX, hdPaths: HD_PATHS });
const signingClient = await SigningStargateClient.connectWithSigner(COSMOS_RPC_URL, signer, clientOptions);
const [oldAddressAccountData, newAddressAccountData] = await signer.getAccounts();
const chainId = await signingClient.getChainId();

console.log('chain id:', chainId);
console.log('old address:', oldAddressAccountData.address); // mạng chính trước đó
console.log('new address:', newAddressAccountData.address); // mạng chính hiện tại
console.log('new evm address:', bech32Converter(PREFIX).toHex(newAddressAccountData.address));
}

main();