11"use client" ;
22import { LazorkitProvider , useWallet } from "@lazorkit/wallet" ;
3- import { Connection , LAMPORTS_PER_SOL , PublicKey } from "@solana/web3.js" ;
3+ import { Connection , SystemProgram , LAMPORTS_PER_SOL , PublicKey } from "@solana/web3.js" ;
44import { useEffect , useState } from "react" ;
5-
65import * as anchor from '@coral-xyz/anchor' ;
76
7+ const connection = new Connection ( process . env . NEXT_PUBLIC_SOLANA_RPC_URL ! ) ;
8+
89export default function Home ( ) {
910
1011 const [ balance , setBalance ] = useState ( 0 ) ;
11-
12- const connection = new Connection ( process . env . NEXT_PUBLIC_SOLANA_RPC_URL ! ) ;
12+ const [ message , setMessage ] = useState ( '' ) ;
13+ const [ signature , setSignature ] = useState ( '' ) ;
1314
1415 const {
1516 smartWalletPubkey,
@@ -20,6 +21,7 @@ export default function Home() {
2021 connect,
2122 disconnect,
2223 signTransaction,
24+ signAndSendTransaction
2325 } = useWallet ( ) ;
2426
2527 const handleConnect = async ( ) => {
@@ -45,49 +47,81 @@ export default function Home() {
4547 const instruction = new anchor . web3 . TransactionInstruction ( {
4648 keys : [ ] ,
4749 programId : new anchor . web3 . PublicKey ( 'Memo1UhkJRfHyvLMcVucJwxXeuD728EqVDDwQDxFMNo' ) ,
48- data : Buffer . from ( 'Hello from LazorKit! 🚀' , 'utf-8' ) ,
50+ data : Buffer . from ( message , 'utf-8' ) ,
4951 } ) ;
5052
5153 try {
5254 const signature = await signTransaction ( instruction ) ;
55+ setSignature ( signature . toString ( ) ) ;
5356 console . log ( 'Transaction signature:' , signature ) ;
5457 } catch ( error ) {
5558 console . error ( 'Signing failed:' , error ) ;
5659 }
5760 } ;
5861
62+ const sendSOL = async ( ) => {
63+ if ( ! smartWalletPubkey ) return ;
64+
65+ const instruction = SystemProgram . transfer ( {
66+ fromPubkey : smartWalletPubkey ,
67+ toPubkey : new PublicKey ( 'MTSLZDJppGh6xUcnrSSbSQE5fgbvCtQ496MqgQTv8c1' ) ,
68+ lamports : 0.1 * LAMPORTS_PER_SOL ,
69+ } ) ;
70+
71+ try {
72+ // Sign and send in one step
73+ const signature = await signAndSendTransaction ( instruction ) ;
74+ console . log ( 'Transfer successful:' , signature ) ;
75+ return signature ;
76+ } catch ( error ) {
77+ console . error ( 'Transaction failed:' , error ) ;
78+ throw error ;
79+ }
80+ } ;
81+
5982 return (
6083 < div >
6184 < LazorkitProvider
62- rpcUrl = "https://api.devnet.solana.com"
63- ipfsUrl = "https://portal.lazor.sh"
64- paymasterUrl = "https://lazorkit-paymaster.onrender.com"
85+ rpcUrl = { process . env . NEXT_PUBLIC_SOLANA_RPC_URL ! }
86+ ipfsUrl = { process . env . NEXT_PUBLIC_IPFS_URL ! }
87+ paymasterUrl = { process . env . NEXT_PUBLIC_PAYMASTER_URL ! }
6588 >
6689 < div style = { { padding : '20px' , display : 'flex' , flexDirection : 'column' , gap : '20px' } } >
6790 < h1 > LazorKit Wallet Demo 1</ h1 >
6891
6992 < div > LazorKitProgram ID: { new anchor . web3 . PublicKey ( '3CFG1eVGpUVAxMeuFnNw7CbBA1GQ746eQDdMWPoFTAD8' ) . toString ( ) } </ div >
7093 < div > Paymaster Wallet: { new anchor . web3 . PublicKey ( 'hij78MKbJSSs15qvkHWTDCtnmba2c1W4r1V22g5sD8w' ) . toString ( ) } </ div >
7194 { ! isConnected ? (
72- < button
73- onClick = { handleConnect }
74- disabled = { isConnecting }
75- >
76- { isConnecting ? 'Connecting...' : 'Connect Wallet' }
77- </ button >
95+ < >
96+ < button
97+ onClick = { handleConnect }
98+ disabled = { isConnecting }
99+ >
100+ { isConnecting ? 'Connecting...' : 'Connect Wallet' }
101+ </ button >
102+ </ >
103+
78104 ) : (
79105 < div style = { { display : 'flex' , flexDirection : 'column' , gap : '10px' } } >
80106 < p >
81- Balance: { balance / LAMPORTS_PER_SOL }
107+ Smart Wallet Address: { smartWalletPubkey ?. toString ( ) }
82108 </ p >
83109 < p >
84- Smart Wallet Address : { smartWalletPubkey ?. toString ( ) }
110+ Balance : { balance / LAMPORTS_PER_SOL }
85111 </ p >
112+ < label > Message</ label >
113+ < input type = "text" value = { message } onChange = { ( e ) => setMessage ( e . target . value ) } />
114+ { signature && < p > Signature: { signature } </ p > }
86115 < button
87116 onClick = { handleSign }
88117 disabled = { isSigning }
89118 >
90119 { isSigning ? 'Signing...' : 'Sign Message' }
120+ </ button > < button
121+ onClick = { sendSOL }
122+ disabled = { isSigning }
123+ >
124+ { isSigning ? 'Sending...' : 'Send SOL' }
91125 </ button >
92126 < button
93127 onClick = { ( ) => disconnect ( ) }
0 commit comments