Introduction
solhtmx is a Solana-native extension to htmx that simplifies blockchain interactions using HTML attributes. It lets you:
- Connect wallets
- Sign transactions
- Interact with Solana
All using declarative HTML, without complex JavaScript.
Problem
Building blockchain apps typically involves:
- Complex wallet SDKs
- Managing connection state
- Handling transaction signing
- Coordinating UI updates
This means lots of JavaScript and careful orchestration of async operations.
Solution
solhtmx extends htmx with Solana-specific attributes:
sol-connect- Connect walletsol-sign- Sign transactionssol-wallet-address- Show wallet addresssol-trigger- React to blockchain events
Connecting a Wallet
<button sol-connect="true"
hx-get="/api/wallet-status"
hx-target="#wallet-info">
Connect Wallet
</button>
Clicking the button:
- Prompts wallet connection
- Triggers
/api/wallet-status - Includes wallet address in headers
- Updates
#wallet-infowith response
Signing Transactions
<button sol-sign="true"
hx-post="/api/prepare-transfer"
hx-vals='{"amount": "0.1"}'
hx-target="#result">
Send 0.1 SOL
</button>
- htmx POSTs to
/api/prepare-transfer - Server builds unsigned transaction
- Server returns HTML + transaction
- solhtmx prompts wallet signature
- Submits signed transaction
- Updates
#resulton confirmation
The server just builds transactions and returns HTML. solhtmx does the rest.
Features
- Wallet connection
- Transaction signing
- Wallet address display
- Event system for updates
- Automatic header injection
Usage
<script src="https://unpkg.com/htmx.org@2.0.0"></script>
<script src="https://unpkg.com/@solana/web3.js@latest"></script>
<script src="path/to/solhtmx.js"></script>
Configure network via meta tags:
<meta name="sol-network" content="devnet">
<meta name="sol-commitment" content="confirmed">
Repo & Docs
Code, examples, docs: github.com/vitorpy/solhtmx
Open source (WTFPL). Contributions welcome.
Conclusion
solhtmx simplifies Solana app development using declarative HTML attributes. Give it a try and share your feedback.