How do I know the correct lamport format for sending Transaction via solana

How do I know the correct format for setting lamport values or variable when sending transaction in web3

Here is my thinking

1 lamport = 1000000000 SOL.

lets assume i want to transfer 0.2 SOL

how will the amount being sent via lamports

Is it like this below

lamports: web3.LAMPORTS_PER_SOL / 0.2

or

lamports: 0.2

or

lamports: 0.2 * 1000000000

please help me with the exact method or format and any further illustration or explanation will be appreciated

Thanks

Hi @nkemo9888, and welcome to the forum!

You would want to do:

let lamports = 0.2 * web3.LAMPORTS_PER_SOL

web3.LAMPORTS_PER_SOL is just a variable that holds the exact value 1000000000 so that you don’t have to remember it and possibly get the value wrong.

And to get however many lamports you want, you just have to multiply the number of SOL by that variable as shown above.

1 Like

Thanks for getting back to me @zicklag. Your information is clear. Thanks for the answer.

just one more question for knowledge sake. in some tutorials, I used to see this line of code

lamports: web3.LAMPORTS_PER_SOL / 100

as amount being sent.

what does that 100 represents and why its used to divide web3.LAMPORTS_PER_SOL.

Hoping to hear from you soon. Thanks

web3.LAMPORTS_PER_SOL / 100 means 0.01 SOL.

So that is the same as doing web3.LAMPORTS_PER_SOL * 0.01.

I’m not sure exactly why they did that in the docs, but it was probably just a quick way to send less than one SOL in the code and they probably weren’t really worried about the exact value.

1 Like