rubyweb3.Web3TransactionLibrary
1.1.5
.NET 8.0
This package targets .NET 8.0. The package is compatible with this framework or higher.
.NET Standard 2.0
This package targets .NET Standard 2.0. The package is compatible with this framework or higher.
dotnet add package rubyweb3.Web3TransactionLibrary --version 1.1.5
NuGet\Install-Package rubyweb3.Web3TransactionLibrary -Version 1.1.5
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="rubyweb3.Web3TransactionLibrary" Version="1.1.5" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="rubyweb3.Web3TransactionLibrary" Version="1.1.5" />
<PackageReference Include="rubyweb3.Web3TransactionLibrary" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add rubyweb3.Web3TransactionLibrary --version 1.1.5
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: rubyweb3.Web3TransactionLibrary, 1.1.5"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package rubyweb3.Web3TransactionLibrary@1.1.5
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=rubyweb3.Web3TransactionLibrary&version=1.1.5
#tool nuget:?package=rubyweb3.Web3TransactionLibrary&version=1.1.5
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Here's the updated README.md file with comprehensive documentation for all the functions in your TransactionService.cs:
Web3TransactionLibrary Documentation
A comprehensive .NET library for Ruby blockchain interactions with Ruby-style address formatting support.
Installation
dotnet add package rubyweb3.Web3TransactionLibrary --version 1.1.3
Quick Start
1. Service Registration
using Microsoft.Extensions.DependencyInjection;
using Web3TransactionLibrary.Extensions;
// Basic registration
services.AddWeb3TransactionService("https://bridge-rpc.rubyscan.io", "rYOUR_PRIVATE_KEY");
// With custom logger
services.AddWeb3TransactionService(
"https://bridge-rpc.rubyscan.io",
"rYOUR_PRIVATE_KEY",
logger);
// Register wallet services
services.AddRubyWeb3Services();
Core Features
Basic Transactions
Send Transaction
public async Task SendRUBY()
{
// Send 0.1 RUBY to a Ruby-formatted address
string transactionHash = await _transactionService.SendTransactionAsync(
"r742d45d5f2e6f9e5a1d3a8b7c6e5f4a3b2c1d0e9f8a7b6", // Ruby format address
1000000000000000000, // Amount in RUBY
25 // Gas price in Gwei (optional, default: 20)
);
Console.WriteLine($"Transaction sent: {transactionHash}");
}
Get Balance
// Get simple balance
decimal balance = await _transactionService.GetBalanceAsync("r742d45d5f2e6f9e5a1d3a8b7c6e5f4a3b2c1d0e9f8a7b6");
Console.WriteLine($"Balance: {balance} RUBY");
// Get detailed balance information
var detailedBalance = await _transactionService.GetBalanceDetailedAsync("r742d45d5f2e6f9e5a1d3a8b7c6e5f4a3b2c1d0e9f8a7b6");
Console.WriteLine($"Address: {detailedBalance.Address}");
Console.WriteLine($"Balance: {detailedBalance.Balance} {detailedBalance.Unit}");
Console.WriteLine($"Retrieved at: {detailedBalance.RetrievedAt}");
Transaction Information
// Get transaction data
var transactionData = await _transactionService.GetTransactionDataAsync(
"r9f8a7b6c5d4e3f2a1b0c9d8e7f6a5b4c3d2e1f0a9b8c7d6e5f4a3b2c1d0e9f8a7b6"
);
Console.WriteLine($"From: {transactionData.FromAddress}");
Console.WriteLine($"To: {transactionData.ToAddress}");
Console.WriteLine($"Value: {transactionData.Value} RUBY");
Console.WriteLine($"Status: {transactionData.Status}");
Console.WriteLine($"Block: {transactionData.BlockNumber}");
// Get raw transaction receipt
var receipt = await _transactionService.GetTransactionReceiptAsync(transactionHash);
Console.WriteLine($"Gas used: {receipt.GasUsed?.Value}");
Console.WriteLine($"Block hash: {receipt.BlockHash}");
Wait for Transaction Confirmation
var txHash = await _transactionService.SendTransactionAsync(toAddress, amount);
var receipt = await _transactionService.WaitForTransactionReceiptAsync(txHash, 60); // 60 second timeout
if (receipt.Status?.Value == 1)
{
Console.WriteLine("Transaction confirmed successfully!");
}
Smart Contract Interactions
Contract Deployment
string bytecode = "0x606060..."; // Your contract bytecode
string abi = "[{...}]"; // Your contract ABI
string contractAddress = await _transactionService.DeployContractAsync(bytecode, abi);
Console.WriteLine($"Contract deployed at: {contractAddress}");
Reading from Contracts (View Functions)
Simple String Return
// Call functions that return strings (name, symbol, etc.)
string tokenName = await _transactionService.CallContractAsync(
contractAddress,
abi,
"name"
);
Console.WriteLine($"Token Name: {tokenName}");
string tokenSymbol = await _transactionService.CallContractAsync(
contractAddress,
abi,
"symbol"
);
Console.WriteLine($"Token Symbol: {tokenSymbol}");
Typed Return Values
using System.Numerics;
// For numeric returns (balance, totalSupply, etc.)
BigInteger totalSupply = await _transactionService.CallContractFunctionAsync<BigInteger>(
contractAddress,
abi,
"totalSupply"
);
Console.WriteLine($"Total Supply: {totalSupply}");
// With parameters
BigInteger balance = await _transactionService.CallContractFunctionAsync<BigInteger>(
contractAddress,
abi,
"balanceOf",
"r742d45d5f2e6f9e5a1d3a8b7c6e5f4a3b2c1d0e9f8a7b6" // Ruby address
);
Console.WriteLine($"Balance: {balance}");
Enhanced Typed Calls
var callRequest = new ContractCallRequest
{
ContractAddress = contractAddress,
Abi = abi,
FunctionName = "balanceOf",
Parameters = new object[] { "r742d45d5f2e6f9e5a1d3a8b7c6e5f4a3b2c1d0e9f8a7b6" }
};
var response = await _transactionService.CallContractAsync<BigInteger>(callRequest);
Console.WriteLine($"Balance: {response.Result}");
Console.WriteLine($"Function: {response.FunctionName}");
Console.WriteLine($"Timestamp: {response.Timestamp}");
Writing to Contracts (State-Changing Functions)
Execute Contract Function
using System.Numerics;
// ERC20 Token Transfer
var txHash = await _transactionService.ExecuteContractFunctionAsync(
contractAddress, // Ruby format contract address
abi, // Contract ABI
"transfer", // Function name
0, // ETH value to send (0 for token transfers)
20, // Gas price in Gwei
"r742d45d5f2e6f9e5a1d3a8b7c6e5f4a3b2c1d0e9f8a7b6", // Recipient (Ruby address)
new BigInteger(1000000000000000000) // Amount in wei (1 token with 18 decimals)
);
Console.WriteLine($"Transfer transaction sent: {txHash}");
Execute with Custom Gas Limit
var txHash = await _transactionService.ExecuteContractFunctionWithGasLimitAsync(
contractAddress,
abi,
"approve",
0, // ETH value
new BigInteger(50000), // Custom gas limit
20, // Gas price
"r742d45d5f2e6f9e5a1d3a8b7c6e5f4a3b2c1d0e9f8a7b6", // Spender
new BigInteger(1000000000000000000) // Amount
);
Enhanced Transaction Execution
var transactionRequest = new ContractTransactionRequest
{
ContractAddress = contractAddress,
Abi = abi,
FunctionName = "transfer",
Parameters = new object[]
{
"r742d45d5f2e6f9e5a1d3a8b7c6e5f4a3b2c1d0e9f8a7b6",
new BigInteger(1000000000000000000)
},
ValueInEth = 0,
GasPriceGwei = 20,
GasLimit = 50000
};
var response = await _transactionService.ExecuteContractTransactionAsync(transactionRequest);
Console.WriteLine($"Transaction Hash: {response.TransactionHash}");
Console.WriteLine($"Function: {response.FunctionName}");
Console.WriteLine($"Value Sent: {response.ValueSent} ETH");
Console.WriteLine($"Timestamp: {response.Timestamp}");
Complete ERC20 Token Example
using System.Numerics;
class Program
{
static async Task Main(string[] args)
{
var services = new ServiceCollection();
services.AddWeb3TransactionService(
"https://bridge-rpc.rubyscan.io",
"r45a4ad4e4ab8dee45da7e46db797121347b274e3b4f0850305868f8e47b106be"
);
var serviceProvider = services.BuildServiceProvider();
var txService = serviceProvider.GetRequiredService<ITransactionService>();
var contractAddress = "r17a788748e934d3e9365f0bf2e5e5a7b73ae8464";
var abi = @"[{
""inputs"": [],
""name"": ""name"",
""outputs"": [{""internalType"": ""string"", ""name"": """", ""type"": ""string""}],
""stateMutability"": ""view"",
""type"": ""function""
},
{
""inputs"": [],
""name"": ""symbol"",
""outputs"": [{""internalType"": ""string"", ""name"": """", ""type"": ""string""}],
""stateMutability"": ""view"",
""type"": ""function""
},
{
""inputs"": [],
""name"": ""decimals"",
""outputs"": [{""internalType"": ""uint8"", ""name"": """", ""type"": ""uint8""}],
""stateMutability"": ""view"",
""type"": ""function""
},
{
""inputs"": [],
""name"": ""totalSupply"",
""outputs"": [{""internalType"": ""uint256"", ""name"": """", ""type"": ""uint256""}],
""stateMutability"": ""view"",
""type"": ""function""
},
{
""inputs"": [{""internalType"": ""address"", ""name"": ""account"", ""type"": ""address""}],
""name"": ""balanceOf"",
""outputs"": [{""internalType"": ""uint256"", ""name"": """", ""type"": ""uint256""}],
""stateMutability"": ""view"",
""type"": ""function""
},
{
""inputs"": [
{""internalType"": ""address"", ""name"": ""recipient"", ""type"": ""address""},
{""internalType"": ""uint256"", ""name"": ""amount"", ""type"": ""uint256""}
],
""name"": ""transfer"",
""outputs"": [{""internalType"": ""bool"", ""name"": """", ""type"": ""bool""}],
""stateMutability"": ""nonpayable"",
""type"": ""function""
},
{
""inputs"": [
{""internalType"": ""address"", ""name"": ""spender"", ""type"": ""address""},
{""internalType"": ""uint256"", ""name"": ""amount"", ""type"": ""uint256""}
],
""name"": ""approve"",
""outputs"": [{""internalType"": ""bool"", ""name"": """", ""type"": ""bool""}],
""stateMutability"": ""nonpayable"",
""type"": ""function""
}]";
try
{
// 1. Read token info
var name = await txService.CallContractAsync(contractAddress, abi, "name");
var symbol = await txService.CallContractAsync(contractAddress, abi, "symbol");
var decimals = await txService.CallContractFunctionAsync<BigInteger>(contractAddress, abi, "decimals");
var totalSupply = await txService.CallContractFunctionAsync<BigInteger>(contractAddress, abi, "totalSupply");
Console.WriteLine($"Token: {name} ({symbol})");
Console.WriteLine($"Decimals: {decimals}");
Console.WriteLine($"Total Supply: {totalSupply}");
// 2. Check balance
var addressToCheck = "r024889737062807ad1b83028f7d0ee986486e799";
var balance = await txService.CallContractFunctionAsync<BigInteger>(
contractAddress,
abi,
"balanceOf",
addressToCheck
);
Console.WriteLine($"Balance of {addressToCheck}: {balance}");
// 3. Transfer tokens
var recipient = "rANOTHER_ADDRESS_HERE";
var amount = new BigInteger(1000000000000000000); // 1 token (18 decimals)
Console.WriteLine($"Transferring {amount} {symbol} to {recipient}...");
var txHash = await txService.ExecuteContractFunctionAsync(
contractAddress,
abi,
"transfer",
0, // No ETH value needed for token transfers
20, // Gas price
recipient,
amount
);
Console.WriteLine($"Transaction sent: {txHash}");
// 4. Wait for confirmation
var receipt = await txService.WaitForTransactionReceiptAsync(txHash);
if (receipt.Status?.Value == 1)
{
Console.WriteLine("Transfer successful!");
}
// 5. Approve tokens for spending (e.g., for DEX)
var spender = "rDEX_CONTRACT_ADDRESS";
var approveAmount = new BigInteger(5000000000000000000); // 5 tokens
var approveTxHash = await txService.ExecuteContractFunctionAsync(
contractAddress,
abi,
"approve",
0,
20,
spender,
approveAmount
);
Console.WriteLine($"Approval transaction: {approveTxHash}");
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
}
}
Parameter Types
When calling contract functions, use these .NET types:
- address:
string(Ruby format:r...) - uint256:
BigInteger - string:
string - bool:
bool - uint8:
BigIntegerorbyte
Best Practices
1. Always Use Try-Catch
try
{
var result = await _transactionService.ExecuteContractFunctionAsync(...);
}
catch (ApplicationException ex)
{
// Blockchain-specific errors
Console.WriteLine($"Contract error: {ex.Message}");
}
catch (Exception ex)
{
// General errors
Console.WriteLine($"Error: {ex.Message}");
}
2. Check ETH Balance for Gas
var ethBalance = await _transactionService.GetBalanceAsync(yourAddress);
if (ethBalance < 0.01m) // Less than 0.01 ETH
{
Console.WriteLine("Warning: Low ETH balance for gas fees");
}
3. Wait for Confirmations
var txHash = await _transactionService.ExecuteContractFunctionAsync(...);
var receipt = await _transactionService.WaitForTransactionReceiptAsync(txHash, 120); // 2 minute timeout
if (receipt.Status?.Value == 1)
{
Console.WriteLine("Transaction confirmed!");
}
4. Use BigInteger for Token Amounts
// Correct: Use BigInteger for token amounts
BigInteger amount = new BigInteger(1000000000000000000); // 1 token with 18 decimals
// Incorrect: Don't use decimal for token transfers
// decimal amount = 1.0m; // WRONG!
Error Handling
Common errors and solutions:
- "transfer amount exceeds balance": Sender doesn't have enough tokens
- "Reverted": Contract execution failed
- "insufficient funds for gas": Not enough ETH for gas fees
- "invalid address": Invalid Ruby address format
- "invalid ABI": ABI JSON is malformed
Dependencies
- .NET 8.0, .NET Standard 2.0
- Nethereum 4.25.0
- Microsoft.Extensions.DependencyInjection
- Microsoft.Extensions.Logging.Abstractions
Support
For issues:
- Check that Ruby addresses are correctly formatted
- Verify you have sufficient ETH for gas fees
- Ensure contract ABI is valid JSON
- Use
BigIntegerfor token amounts - Check transaction receipts for detailed error messages
License
MIT License - See LICENSE file for details.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- Microsoft.Extensions.DependencyInjection (>= 6.0.1)
- Microsoft.Extensions.Logging.Abstractions (>= 6.0.4)
- Nethereum.Accounts (>= 4.25.0)
- Nethereum.Web3 (>= 4.25.0)
-
net8.0
- Microsoft.Extensions.DependencyInjection (>= 8.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.0)
- Nethereum.Accounts (>= 4.25.0)
- Nethereum.Web3 (>= 4.25.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.1.5 | 570 | 12/1/2025 |
| 1.1.4 | 468 | 12/1/2025 |
| 1.1.3 | 467 | 12/1/2025 |
| 1.1.2 | 466 | 12/1/2025 |
| 1.1.1 | 463 | 12/1/2025 |
| 1.1.0 | 465 | 12/1/2025 |
| 1.0.9 | 461 | 12/1/2025 |
| 1.0.8 | 459 | 12/1/2025 |
| 1.0.7 | 464 | 12/1/2025 |
| 1.0.6 | 179 | 9/24/2025 |
| 1.0.5 | 180 | 9/23/2025 |
| 1.0.4 | 174 | 9/22/2025 |
| 1.0.3 | 190 | 9/22/2025 |
| 1.0.2 | 174 | 9/22/2025 |
| 1.0.1 | 199 | 9/22/2025 |
| 1.0.0 | 195 | 9/22/2025 |