Search code examples
node.jssolanasolana-web3jssolana-transaction-instruction

Sending SOL using messages in web3/solana


I'm following the Solana docs and trying to send a transaction through message which according to Solana docs is another way to construct a transaction. I have no problem sending the transaction but nowhere I can mention the amount that I want to send. I have been following this link and had a hard time figuring out add amount. I suspected that I can mention the amount like web3.SYSTEM_INSTRUCTION_LAYOUTS.Transfer({from, to, lamports}) but apparently it provides me an error and when I look into the web3 library I cannot find SYSTEM_INSTRUCTION_LAYOUTS.Transfer

Can someone please point out how I can add the amount to the transaction instruction?


Solution

  • So the SYSTEM_INSTRUCTION_LAYOUTS.Transfer has fields where you can provide the instruction along with it you can provide lamports in bigint. This will allow you to transfer the sol using messages

    Something like this

    let layoutFields = Object.assign({ instruction: type.index , lamports : BigInt(amount * LAMPORTS_PER_SOL)});