2

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.

Ray
  • 47
  • 3

1 Answers1

0

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.

  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 28 '22 at 11:35