@@ -463,24 +463,30 @@ export function createActions({ connectors, logger: inputLogger, runtime, store
463463 * @returns Promise resolving with the signature for the airdrop transaction.
464464 */
465465 async function requestAirdrop ( address : Address , lamports : Lamports ) {
466- if ( ! ( 'requestAirdrop' in runtime . rpc ) ) {
467- throw new Error ( 'The current RPC endpoint does not support airdrops.' ) ;
466+ try {
467+ const factory = airdropFactory ( {
468+ rpc : runtime . rpc ,
469+ rpcSubscriptions : runtime . rpcSubscriptions ,
470+ } as Parameters < typeof airdropFactory > [ 0 ] ) ;
471+ const signature = await factory ( {
472+ commitment : getCommitment ( 'confirmed' ) ,
473+ lamports,
474+ recipientAddress : address ,
475+ } ) ;
476+ logger ( {
477+ data : { address : address . toString ( ) , lamports : lamports . toString ( ) , signature } ,
478+ level : 'info' ,
479+ message : 'airdrop requested' ,
480+ } ) ;
481+ return signature ;
482+ } catch ( error ) {
483+ logger ( {
484+ data : { address : address . toString ( ) , lamports : lamports . toString ( ) , ...formatError ( error ) } ,
485+ level : 'error' ,
486+ message : 'airdrop request failed' ,
487+ } ) ;
488+ throw error ;
468489 }
469- const factory = airdropFactory ( {
470- rpc : runtime . rpc ,
471- rpcSubscriptions : runtime . rpcSubscriptions ,
472- } as Parameters < typeof airdropFactory > [ 0 ] ) ;
473- const signature = await factory ( {
474- commitment : getCommitment ( 'confirmed' ) ,
475- lamports,
476- recipientAddress : address ,
477- } ) ;
478- logger ( {
479- data : { address : address . toString ( ) , lamports : lamports . toString ( ) , signature } ,
480- level : 'info' ,
481- message : 'airdrop requested' ,
482- } ) ;
483- return signature ;
484490 }
485491
486492 return {
0 commit comments