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.
2 Answers
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.
The first picture is my provider, where I get my provider, wallet and keypair (you don't need this one TBH).
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?
-
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