百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
S

Solnet

> 开发工具
开源

Solana 的 .NET SDK 和集成库。

391 stars0 点赞3 次浏览
访问官网GitHub

工具介绍

Solana 的 .NET SDK 和集成库。

Features

  • Full JSON RPC API coverage
  • Full Streaming JSON RPC API coverage
  • Wallet and accounts (Phantom and solana-keygen compatible)
  • Keystore (Phantom and solana-keygen compatible)
  • Transaction decoding/encoding (base64 and wire format)
  • Message decoding/encoding (base64 and wire format)
  • Instruction decompilation
  • TokenWallet object to send SPL tokens and JIT provisioning of Associated Token Accounts
  • Programs
    • Native Programs
      • System Program
      • Stake Program
    • Solana Program Library (SPL)
      • Compute Budget Program
      • Account Compression Program
      • Governance Program
      • StakePool Program
      • Address Lookup Table Program
      • Memo Program
      • Token Program
      • Token Swap Program
      • Associated Token Account Program
      • Name Service Program
      • Shared Memory Program

For maintainability and due to the size/complexity of some other programs, this repository focuses on Solana's Native Programs and SPL programs. For other commonly used programs see:

  • Serum
  • Mango
  • Pyth

Maintained by Bifrost

  • Metaplex
  • Raydium
  • JupiterSwap
  • JupiterPerps
  • Moonshot
  • Pumpfun
  • Ore

Requirements

  • .NET 6.0 (deprecated)
  • .NET 8.0+ (recommended)

Dependencies

  • BifrostSecurity
  • Portable.BouncyCastle (optional)

Installation

Use the .NET CLI to install Solnet packages into your project (choose the ones you need):

powershell
# Rpc client and streaming
 dotnet add package Solana.Rpc
 dotnet add package Solana.Programs

# Wallets and keys
 dotnet add package Solana.Wallet

# Token helpers
 dotnet add package Solana.Extensions

# Keystore utilities
 dotnet add package Solana.Keystore

Latest Packages on NuGet:

  • Solana.Rpc
  • Solana.Wallet
  • Solana.Programs
  • Solana.Extensions
  • Solana.Keystore

Quickstart

A minimal example to fetch a balance and send a memo:

…

Examples

The Solnet.Examples project contains runnable code examples. Some examples derive accounts from a seed and may fail if an account at a derivation index already exists with the same seed. If you see simulation logs like account address is ... already in use, increment the derivation index (e.g., wallet.GetAccount(index + 1)).

Wallets

The Solnet.Wallet project implements wallet and key generation compatible with both solana-keygen and Phantom.

Initialize a keypair from a secret key

csharp
var account = Account.FromSecretKey("");

Initialize a wallet (Phantom-compatible by default)

csharp
var wallet = new Wallet("mnemonic words ...", WordList.English);
var account = wallet.GetAccount(10);

Initialize a wallet compatible with solana-keygen

csharp
var wallet = new Wallet("mnemonic words ...", WordList.English, "passphrase", SeedMode.Bip39);
var account = wallet.Account; // solana-keygen uses a fixed derivation path

Generating new wallets

csharp
var newMnemonic = new Mnemonic(WordList.English, WordCount.Twelve);
var wallet = new Wallet(newMnemonic);

KeyStore

The Solnet.KeyStore project enables secure storage of keys, seeds, and mnemonics. It implements the Web3 Secret Storage Definition and includes SolanaKeyStoreService to read keys generated by solana-keygen.

Secret KeyStore Service

csharp
var secretKeyStoreService = new SecretKeyStoreService();
var jsonString = secretKeyStoreService.EncryptAndGenerateDefaultKeyStoreAsJson(password, data, address);

try
{
    var decrypted = KeyStore.DecryptKeyStoreFromJson(password, jsonString);
}
catch (Exception)
{
    Console.WriteLine("Invalid password!");
}

Solana KeyStore Service

csharp
var solanaKeyStoreService = new SolanaKeyStoreService();
var wallet = solanaKeyStoreService.RestoreKeystore(filePath, passphrase);

RPC and Streaming RPC

The Solnet.Rpc project contains a full implementation of the Solana JSON RPC.

ClientFactory pattern

csharp
var rpcClient = ClientFactory.GetClient(Cluster.MainNet, logger);
var paidClient = ClientFactory.GetClient("https://your.paid.rpc", logger);
var streamingRpcClient = ClientFactory.GetStreamingClient(Cluster.MainNet, logger);

Using the RPC

…

Using the Streaming RPC

csharp
var txSig = rpcClient.SendTransaction(tx);
var subscription = streamingRpcClient.SubscribeSignature(txSig.Result, (state, response) =>
{
    // handle confirmation
}, Commitment.Finalized);

Sending a transaction

Important: Understanding priority fees

Poorly optimized transactions can get dropped due to high compute demand. Always specify both compute unit limit and price to improve inclusion probability.

csharp
var txBuilder = new TransactionBuilder()
    .AddInstruction(ComputeBudgetProgram.SetComputeUnitLimit(30000))
    .AddInstruction(ComputeBudgetProgram.SetComputeUnitPrice(1000000));
…

Create, Initialize and Mint

…

Transfer a Token to a new Token Account

…

Transaction and Message decoding

csharp
var tx = Transaction.Deserialize(txData);
var msg = Message.Deserialize(msgData);
var signedTx = Transaction.Populate(msg, new List { account.Sign(msgData) });

Programs

The Solnet.Programs project contains implementations of several Native and SPL programs. See Solnet.Examples for more depth, including multi-signature operations.

Hello Solana World

csharp
var memoInstruction = MemoProgram.NewMemo(wallet.Account, "Hello Solana World, using Solnet :)");

var recentHash = rpcClient.GetLatestBlockHash();

var tx = new TransactionBuilder()
    .SetFeePayer(wallet.Account)
    .AddInstruction(ComputeBudgetProgram.SetComputeUnitLimit(30000))
    .AddInstruction(ComputeBudgetProgram.SetComputeUnitPrice(1000000))
    .AddInstruction(memoInstruction)
    .SetRecentBlockHash(recentHash.Result.Value.Blockhash)
    .Build(wallet.Account);

Creating and sending tokens to an Associated Token Account

…

Creating and extending an Address Lookup Table for a complex transaction

…

This pattern is useful when a later transaction needs more account addresses than fit comfortably in the legacy message format. In Solnet, you typically create and populate the ALT with TransactionBuilder, wait for confirmation, and then reference it from a VersionedTransaction when building the larger v0 message.

v0 Transaction Execution

…

v1 Transaction Execution

v1 Transactions no longer require the computebudget program, but instead require TransactionConfig. For more details on v1 can be found here: Sending v1 Transactions

…

Instruction decoding

csharp
var msg = Message.Deserialize(msgBase64);
var decodedInstructions = InstructionDecoder.DecodeInstructions(msg);

Contribution

We encourage everyone to contribute, submit issues and PRs, and join discussions. Every kind of help is welcome.

Legacy Maintainers

  • Hugo - murlokito
  • Tiago - tiago

Current Maintainers

  • Nathan - BifrostTitan

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

C#cryptocurrencycsharpdefidotnet

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类开发工具
定价开源

> 相关工具

V
VS Code
流行的开源代码编辑器
G
Git
分布式版本控制系统
V
Vite
下一代前端构建工具