0

I want to create an escrow program in Rust on Solana with the following requirements: Anyone can send an amount to the escrow, a lottery function runs on the backend to select a winner, and the NFT is sent to the winner while the amount sent by the winner goes to the admin. The other participants get their SOL tokens back.

I'm new to Solana, and when I checked most of the repository examples, they were focused on swap exchange escrow accounts for tokens X to tokens Y. I tried to work on it, but I couldn't complete this specific task. I need an escrow solution that only deals with SOL tokens, where the admin can select the winner, the escrow holds the amount, and there is a cancel function for participants to retrieve their SOL tokens if needed.

2
  • For the escrow account you can follow this link paulx.dev/blog/2021/01/14/programming-on-solana-an-introduction Commented Sep 15, 2023 at 5:55
  • Thanks for the comment @IshaPadalia. Paulx used Solana's old version as well as a totally different logic as he takes two tokens and swaps these tokens from ESCROW. So I'm changing my logic from here but facing some errors because of getting and releasing the SOL amount from ESCOW.
    – Bobz
    Commented Sep 15, 2023 at 7:44

2 Answers 2

0

you have to be more specific about your question.

here is the flow you need : For each participant that sends SOL, you create an escrow which will hold their SOL. So 10 participants = 10 escrow accounts. You can use the repo examples you found for that.

The cancel method just close the escrow and sends back the sol to the participant.

The select winner method sends the sol to the admin and the nft to the winner.

For each escrow, IMO you should also create a PDA that contains data such as : participant's wallet address, SOL amount, may be "lottery id" or equivalent

For each lottery you should also have a PDA with data such as NFT mint address, and another PDA that will hold the NFT

When you cancel, you have to check on the PDA that the canceller and the escrow are linked thru the PDA (security check)

There is actually a lot to say about your program idea, you have to be more specific, otherwise i'm going to writes 10K lines in my reply ;)

5
  • Thanks for sharing the logic, but I'm facing the issue of getting the amount in ESCROW and dealing through the admin as I don't have much experience in rust side.
    – Bobz
    Commented Sep 15, 2023 at 7:40
  • if you want to do it in rust : 1) you have to define the escrow's struct in your program 2) in your instruction, you have to provide the escrow address you want to read 3) in your code you can do : ctx.accounts.escrow_account.amount escrow_account being the name of your account in the struct of your instruction amount being the name of your field where you store the amount in the escrow If you want more code, please post a new question regarding this specific point, and i will give code examples
    – Effe2
    Commented Sep 15, 2023 at 8:23
  • I define these things but face different errors. I'd be very thankful to you if you share relevant code related to ESCROW.
    – Bobz
    Commented Sep 15, 2023 at 10:11
  • yes i will but please start a new question in order to keep things clear
    – Effe2
    Commented Sep 15, 2023 at 10:16
  • Thanks, bro. check this solana.stackexchange.com/questions/7604/…
    – Bobz
    Commented Sep 15, 2023 at 10:31
0

I just found this video yesterday and it should help you understand how to build what you're trying to build.

I highly suggest you take the time to watch it.

https://www.youtube.com/watch?v=uIQDNVbaQn8

1
  • 1
    Thanks for the suggestion but I checked this video, He doesn't use ESCROW in the lottery. He transfers the SOL directly onto the Admin account.
    – Bobz
    Commented Sep 15, 2023 at 7:38

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.