|
| 1 | +import { connect, keyStores } from "near-api-js"; |
| 2 | +import dotenv from "dotenv"; |
| 3 | +import chalk from "chalk"; |
| 4 | +import { Buffer } from "buffer"; |
| 5 | + |
| 6 | +dotenv.config(); |
| 7 | + |
| 8 | +interface NearConfig { |
| 9 | + networkId: string; |
| 10 | + nodeUrl: string; |
| 11 | +} |
| 12 | + |
| 13 | +async function get_staged_code_hash(config: NearConfig): Promise<void> { |
| 14 | + const contractId = process.env.OMNI_BRIDGE_ACCOUNT_ID || "" |
| 15 | + |
| 16 | + if (!contractId) { |
| 17 | + console.log(chalk.yellow(`${contractId} ID not provided, skipping...`)); |
| 18 | + return; |
| 19 | + } |
| 20 | + |
| 21 | + |
| 22 | + const keyStore = new keyStores.InMemoryKeyStore(); |
| 23 | + const nearConnection = await connect({ |
| 24 | + networkId: config.networkId, |
| 25 | + keyStore, |
| 26 | + nodeUrl: config.nodeUrl, |
| 27 | + headers: {}, |
| 28 | + }); |
| 29 | + const account = await nearConnection.account("dummy.near"); |
| 30 | + |
| 31 | + try { |
| 32 | + const up_staged_code_hash = await account.viewFunction({ |
| 33 | + contractId, |
| 34 | + methodName: "up_staged_code_hash", |
| 35 | + args: {}, |
| 36 | + }); |
| 37 | + const buffer = Buffer.from(up_staged_code_hash); |
| 38 | + const base64Encoded = buffer.toString("base64"); |
| 39 | + |
| 40 | + console.log("Base64:", base64Encoded); |
| 41 | + } catch (e) { |
| 42 | + console.log( |
| 43 | + chalk.yellow( |
| 44 | + `up_staged_code_hash function not found or failed`, |
| 45 | + ), |
| 46 | + ); |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +const nearConfig: NearConfig = { |
| 51 | + networkId: process.env.NETWORK_NEAR || "testnet", |
| 52 | + nodeUrl: `https://rpc.${process.env.NETWORK_NEAR || "testnet"}.near.org`, |
| 53 | +}; |
| 54 | +get_staged_code_hash(nearConfig) |
0 commit comments