我正在尝试使用Solana来解决特定的问题。
我使用NPM来攻击Solana的API,所使用的包是@solana/web3.js和@solana/spl-token。我已经能够创建一个成功的连接和生成键盘。我希望能够保存生成的键盘,但我面临的问题是它被编码了,第二个要突出显示的问题是我何时使用.toString();它可以很好地解码它,但不能在空投中使用。
const solanaWeb3 = require("@solana/web3.js"),
const solanatoken = require("@solana/spl-token");
(async () => {
// Connect to cluster
var connection = new solanaWeb3.Connection(
solanaWeb3.clusterApiUrl("devnet"),
"confirmed"
);
// Generate a new wallet keypair and airdrop SOL
var wallet = solanaWeb3.Keypair.generate();
console.log("public key...", wallet.publicKey)
// The stringPK is an example of what wallet.publicKey returns. When taking wallet.publicKey and using .toString(); it returns the decoded publicKey but that can't be used in an airdrop.
const stringPK = `_bn: <BN: e8a4421b46f76fdeac76819ab21708cc4a4b9c9c7fc2a22e373443539cee1a81>`;
console.log("private key...", JSON.stringify(wallet.secretKey.toString()));
console.log(solanaWeb3.PublicKey.decode(wallet.publicKey));
var airdropSignature = await connection.requestAirdrop(
stringPK,
solanaWeb3.LAMPORTS_PER_SOL
);
//wait for airdrop confirmation
await connection.confirmTransaction(airdropSignature);
let account = await connection.getAccountInfo(wallet.publicKey);
console.log(account);
})();https://stackoverflow.com/questions/69369516
复制相似问题