【发布时间】:2022-07-08 10:14:15
【问题描述】:
我正在尝试按照一些代码来测试在代码中实例化钱包。我正在硬编码私钥(显然不会在 prod 中这样做)只是为了看看一切是如何工作的。我收到此错误:
throw new Error('bad secret key size');
^
Error: bad secret key size
我的代码如下:
import { Connection, Keypair, Transaction } from '@solana/web3.js'
import fetch from 'cross-fetch'
import { Wallet } from '@project-serum/anchor'
import bs58 from 'bs58'
const connection = new Connection('https://ssc-dao.genesysgo.net')
const PRIVATE_KEY = 'my secret key is this very dumb long confusing and unnecessary string'
const wallet = new Wallet(Keypair.fromSecretKey(bs58.decode(process.env.PRIVATE_KEY || '')))
【问题讨论】:
标签: javascript solana solana-web3js