9

OK, Im trying to make transactions on backend(Nodejs). I want to make transactions that are made on the backend and want to store there as well(This parts easy). I just want to make sure, Because I want to avoid wallet approval. I want to use a wallets keypair to sign transactions.

1
  • You need to create a transaction and then provide a signer object to the sendAndConfirmTransaction() function.
    – a_rubik
    Commented Aug 11, 2022 at 16:11

2 Answers 2

3

So what I did was, To make transactions on backend, You need a wallet right. I saved a private key on the .env file and used that as my private key, Then I created a keypair from it, Then I imported a Wallet from solanaweb3 or anchor, You can look it up, Then I created a wallet using that keypair, Which made it easy to sign my transactions and used that wallet for my smart contract interaction and signing.

1
  • Could you share the code (without the private key ofcourse)
    – C.OG
    Commented Aug 12, 2022 at 12:28
3

enter image description here

The first picture is my provider, where I get my provider, wallet and keypair (you don't need this one TBH).

enter image description here

In the second picture I'm fetching the same parameters I exported and using them to call and sign my blockchain functions. Simple ain't it?

2
  • Hi..i just wanted to know if it's safe to store the private key in .env folder in say a next js app? Is it possible for someone to get hold of this private key from the frontend and steal all the assets? Pardon me if this question seems naive becoz i m new to solana ..thanks for your help Commented Aug 15, 2022 at 20:42
  • @JoyMukherjee Hi...In my knowledge they cannot...I guess..anythings possible. What you can do is use the env variable directly, instead I did was store it in a variable, Thats dangerous. Use it like e.g: process.env.SECRETKEY directly instead of storing it in a variable which defeats the purpose of using the env file. Also, ENV file is tied to your Linux system/VM(Virtual Machine) where its hosted on and its not possible for someone to access it, Because it is accessible to only that VM. Commented Aug 16, 2022 at 6:19

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.