1

a bit new to the Solana development, I am trying to create a program that can send a certain amount of Solana from my wallet to a particular address. I found some code but am not really understanding how it works. I am also having trouble understanding how I can switch from devnet to mainnet. I tried switching to mainnet beta but it wasn't really working. Any help would be helpful.

Thanking you in advance.

2 Answers 2

2

For python you can send SOL as follows:

from solana.rpc.api import Client
from solana.keypair import Keypair
from solana.transaction import Transaction
from solana.system_program import TransferParams, transfer

LAMPORT_PER_SOL = 1000000000

client: Client = Client("https://api.devnet.solana.com")

sender = Keypair.generate()
receiver = Keypair.generate()

airdrop = client.request_airdrop(sender.public_key, 1 * LAMPORT_PER_SOL)
airdrop_signature = airdrop["result"]
client.confirm_transaction(airdrop_signature)

transaction = Transaction().add(transfer(TransferParams(
    from_pubkey=sender.public_key,
    to_pubkey=receiver.public_key,
    lamports=1_000_000)
))

client.send_transaction(transaction, sender)

The above code sends SOL from the sender to receiver

3
  • Okay this helps a bit, but, how can I transition from devnet to mainnet? Commented Jul 27, 2022 at 21:38
  • @TanayUpreti Just update the Client url to point to a mainnet RPC
    – Jacob Creech
    Commented Jul 27, 2022 at 21:47
  • please ask new questions in new posts rather than in the comments
    – trent.sol
    Commented Jul 27, 2022 at 23:46
0

Please how do i so solana transfer, the codes seems to be emitting an issue from solana's own api file.

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.