Skip to content

Commit

Permalink
[send-nft] ✨ Support using private key for signer
Browse files Browse the repository at this point in the history
  • Loading branch information
williamchong committed Nov 3, 2023
1 parent 8cb62ea commit 82dcf4b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
4 changes: 3 additions & 1 deletion send-nft/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ Change the data in `./list.csv` (reference `./list_example.csv`)

Change the data in `./config/config.js`

Where `MNEMONIC` is your mnemonic phrase , `WAIT_TIME` is wait time after console (before send)
DEFINE `MNEMONIC` or `PRIVATE_KEY`

Where `MNEMONIC` is your mnemonic phrase, `PRIVATE_KEY` is the hex of private key, `WAIT_TIME` is wait time after console (before send)

## Usage

Expand Down
2 changes: 1 addition & 1 deletion send-nft/config/config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const { MNEMONIC, IS_TESTNET } = process.env;
export const { MNEMONIC, PRIVATE_KEY, IS_TESTNET } = process.env;
export const MEMO = '';
export const WAIT_TIME = 10000; // In ms

Expand Down
9 changes: 6 additions & 3 deletions send-nft/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DirectSecp256k1HdWallet } from '@cosmjs/proto-signing';
import { DirectSecp256k1HdWallet, DirectSecp256k1Wallet } from '@cosmjs/proto-signing';
import { TimeoutError } from '@cosmjs/stargate';
import { ISCNQueryClient, ISCNSigningClient } from '@likecoin/iscn-js';
import fs from 'fs';
Expand All @@ -10,7 +10,7 @@ import { PageRequest } from 'cosmjs-types/cosmos/base/query/v1beta1/pagination.j
import { TxRaw } from 'cosmjs-types/cosmos/tx/v1beta1/tx.js';
/* eslint-enable import/extensions */
import {
MNEMONIC, WAIT_TIME, RPC_ENDPOINT, DENOM, MEMO,
MNEMONIC, PRIVATE_KEY, WAIT_TIME, RPC_ENDPOINT, DENOM, MEMO,
// eslint-disable-next-line import/extensions
} from './config/config.js';

Expand Down Expand Up @@ -86,7 +86,10 @@ function getGasFee(count) {
async function run() {
try {
const data = await readCsv('list.csv');
const signer = await DirectSecp256k1HdWallet.fromMnemonic(MNEMONIC, { prefix: 'like' });
if (!MNEMONIC && !PRIVATE_KEY) throw new Error('need MNEMONIC or PRIVATE_KEY');
const signer = MNEMONIC
? await DirectSecp256k1HdWallet.fromMnemonic(MNEMONIC, { prefix: 'like' })
: await DirectSecp256k1Wallet.fromKey(Buffer.from(PRIVATE_KEY, 'hex'), 'like');
const [firstAccount] = await signer.getAccounts();

const nftsDataObject = {};
Expand Down

0 comments on commit 82dcf4b

Please sign in to comment.