Skip to content

Commit

Permalink
refact deploy not use cosmwasm directly
Browse files Browse the repository at this point in the history
  • Loading branch information
fgregoribattista committed Dec 11, 2023
1 parent 2262251 commit 5ff0469
Showing 1 changed file with 45 additions and 42 deletions.
87 changes: 45 additions & 42 deletions scripts/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,67 +1,70 @@
import 'dotenv/config.js'
import 'dotenv/config.js';
import {
deployContract,
executeContract,
queryContract,
uploadContract,
} from './helpers.js'
import { GasPrice, setupNodeLocal } from 'cosmwasm'
import { DirectSecp256k1HdWallet } from '@cosmjs/proto-signing'
import { writeFile } from 'fs'
import { testnet } from './deploy_configs.js'
import { join } from 'path'
} from './helpers.js';
import { DirectSecp256k1HdWallet, OfflineSigner } from '@cosmjs/proto-signing';
import { writeFile } from 'fs';
import { testnet } from './deploy_configs.js';
import { join } from 'path';

import { GasPrice } from '@cosmjs/stargate';
import { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate';

// consts
const ARTIFACTS_PATH = '../artifacts'

function createConfig(
chainId?: string,
rpcEndpoint?: string,
prefix?: string,
gasPrice?: GasPrice,
) {
if (
chainId === undefined ||
rpcEndpoint === undefined ||
prefix === undefined
) {
throw new Error('chainId, rpcEndpoint, and prefix must all be defined')
}
const ARTIFACTS_PATH = '../artifacts';

if (gasPrice === undefined) {
gasPrice = GasPrice.fromString('0.025uosmo')
}
async function createWallet(
mnemonic: string,
prefixValue: string
): Promise<OfflineSigner> {
// const mnemonic =
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(mnemonic, {
prefix: prefixValue,
});

return { chainId, rpcEndpoint, prefix, gasPrice }
return wallet;
}

// main
async function main() {
const mnemonic = process.env.MNEMONIC
const mnemonic = process.env.MNEMONIC;

// just check mnemonic has actually been defined
if (mnemonic === null || mnemonic === undefined) {
const message = `mnemonic undefined`
const message = `mnemonic undefined`;

throw new Error(message)
throw new Error(message);
}

let chainId = process.env.CHAINID
let rpcEndpoint = process.env.RPC
let prefix = process.env.PREFIX
let chainId = process.env.CHAINID;
let rpcEndpoint = process.env.RPC;
let prefix = process.env.PREFIX;
if (
chainId === undefined ||
rpcEndpoint === undefined ||
prefix === undefined
) {
throw new Error('chainId, rpcEndpoint, and prefix must all be defined');
}

const config = createConfig(chainId, rpcEndpoint, prefix)
let deployConfig: Config = testnet;
const isTestnet = process.env.NETWORK === 'testnet';

const client = await setupNodeLocal(config, mnemonic)
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(mnemonic, {
prefix: config.prefix,
})
let deployConfig: Config = testnet
const isTestnet = process.env.NETWORK === 'testnet'
if (!rpcEndpoint) return;

const wallet = await createWallet(mnemonic, prefix);

const [account] = await wallet.getAccounts();
console.log(`Wallet address from seed: ${account.address}`);

const [account] = await wallet.getAccounts()
const client = await SigningCosmWasmClient.connectWithSigner(
rpcEndpoint,
wallet,
{ gasPrice: GasPrice.fromString('0.025uosmo') }
);

console.log(`Wallet address from seed: ${account.address}`)

///
/// Upload CW20 Contract
Expand Down

0 comments on commit 5ff0469

Please sign in to comment.