I am trying to buy NFT from Magic Eden Solana with node js/typescript script,
at first I used solana CLI to get the keypair by using the command below
cat .../.config/solana/id.json
typescript :
let Array_key = [98, 90, 131, ...]; ```got it using solana cli from .../.config/solana/id.json```
let secret = Uint8Array.from(Array_key)
let signers = Keypair.fromSecretKey(Uint8Array.from(secrete))
const connection = new Connection("https://api.mainnet-beta.solana.com",'confirmed');
let publickey = new PublicKey("2Eod3hjZBJZzGYSJVrVtRC3UMZeonZYfUScmAy1tjD5c");```Wallet address```
let allocateTransaction = new Transaction({
feePayer: publickey,
});
const databuf = Buffer.from(parsed_buy_response['tx']['data'], "hex");```from https://api-mainnet.magiceden.io/v2/instructions/buy_now```
const keys: AccountMeta[] = await generateAccountList(MintAddress,publickey, connection);```function used from transaction.ts https://github.com/solanasoulja/sol-nft-sniper/blob/main/src/views/HomeView/transaction.ts```
allocateTransaction.add(new TransactionInstruction({
keys: keys,
programId: publickey,
data: databuf,
}));
await sendAndConfirmTransaction(connection, allocateTransaction, [signers]).then(resolve => {
console.log('transaction sent')
console.log(resolve)
}).catch(err => {
console.log('err at sending transaction')
console.log(err)
})
and the output is Error: unknown signer xxxxxxxxxxxxxxx, noting that my wallet address is different than the signer, I don't know why I am getting a different signer.
I tried different method by generating the keypair using bip39 method as shown below:
async getKeyPair(mnemomic) {
const seed = bip39.mnemonicToSeedSync(mnemomic).slice(0, 32);
console.log(seed)
// let _KeyPairseed = await web3.PublicKey.createWithSeed(publicKey, seed, publicKey)
// console.log(_KeyPairseed)
const keypair = Keypair.fromSeed(seed);
console.log(keypair)
return keypair;
};
I get different error => verification error
not sure if I am missing a step.
If someone else is going through this problem, here is the answer. Make sure the wallet is written Anchor.toml and this same wallet should match the wallet in your test file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With