The road to landing your dream job can be a bumpy one. Luckily there are experts like Jeff Lovejoy, SumUp’s Future Talent Programme Manager, who are here to help guide you and make the process a…
Solana is a decentralized blockchain that allows you to run decentralized apps.
I have been exploring this world a little in the last few months and would like to share some nice stuff about the Rust API for Solana. It has been being a good starting point for me.
Navigate to the folder containing the project and open your favorite IDE / Editor. I’m using Visual Studio Code.
Create a lib.rs file.
Add the following dependencies to the .toml file.
Create an RPC client on main.rs, that will be injected in the functions on lib.rs file. This way we centralize the configuration.
Also for simplicity, I’m injecting the RPC client instead of creating a struct with the client, for example.
Imports to be included on lib.rs file:
I’ll create a method to return a new keypair, only to reduce the dependencies of the rust SDK inside of the main file and better centralize the calls to the Solana network.
In this example, for every execution, we will be creating new keypairs for both sender and receiver.
The following snippet shows the code to request an airdrop.
The methods receive the amount in lamports, which represents 0.000000001 SOL. Therefore, it’s necessary to calculate the value in lamports prior to sending it to the RPC client methods.
We can also check the balance using an account’s public key. The balance is returned in lamports, so we can format it by dividing by our created constant.
And now the transfer between our two newly created accounts.
We are almost finishing it. Here goes the snippet of the full execution in the main.rs file:
Run cargo run
to execute it. The output should be as follows:
Here you can see the transfer transaction:
And that is all, folks. Hope it may have been useful for other that, like myself, are learning Rust and Solana.
See you in the next one!
Fragmentos de saudade da cidade viva (sem o peso da pandemia). Texto publicado em Março de 2018 e reformulado em 2021. Recife é onde eu nasci, me criei, estudei, é a cidade que eu amo. Nesse momento…
My brother is a smart boy. He’s interested in things like parties, cars, girls, etc. See, there’s nothing connected with software but I really wanted to share with him what I learned about…
In the world before the fear we walked like lions. In a pride. Not any more. If you listen carefully you can hear the beating heart of loneliness.