4

I am trying to call a certain function of my custom smart contract on the solana blockchain using solana web3. I am trying to sign the function call using my private key instead of signing it through the phantom wallet. Is there any possible way to do that? the code which I am using:

adminKeypair=bs58.decode(privateKey) //private key is a string
let adminSigner = Keypair.fromSecretKey(adminKeypair);

await program.rpc.enterUserInfo({
 accounts: {
        signer: adminSigner.publicKey,
        systemProgram: SystemProgram.programId,
      },
})

The error which I am getting is that:

Uncaught (in promise) Error: Signature verification failed
    at Transaction.serialize (transaction.ts:736:1)
    at w.send (provider.ts:116:1)
    at async Object.enterUserInfo (rpc.ts:26:1)
    at async enterUserInfo (utils.js:190:1)
    at async _enterUserInfo (App.js:135:1)

1 Answer 1

2

You have to add the signers property with the keypair inside:

await program.rpc.enterUserInfo({
  accounts: {
    signer: adminSigner.publicKey,
    systemProgram: SystemProgram.programId,
  },
  signers: [adminSigner],
})
1
  • Im doing this in react. Even if I dont use the phantom wallet connected to the app explicitly, the transaction has two signers: adminSigner and wallet. Is there anyway to stop the wallet id from signing
    – fahad
    Aug 5, 2022 at 12:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.