Skip to main content

Mainnet Cosmos Part

CosmJS

In order to use the cosmJS library function in the CrossFi network, you need to patch the cosmJS library as in the example: 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.mainnet.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); // previous mainnet network
console.log('new address:', newAddressAccountData.address); // current mainnet network
console.log('new evm address:', bech32Converter(PREFIX).toHex(newAddressAccountData.address));
}

main();