Nethereum

.NET 애플리케이션을 위해 Nethereum을 사용하여 256 Blocks에 연결하세요

Nethereum은 이더리움 노드, 스마트 컨트랙트 및 더 넓은 생태계와 상호작용하기 위한 완전한 구현을 제공하는 .NET용 이더리움 통합 라이브러리입니다.

설치

NuGet을 통해 Nethereum을 설치하세요:

dotnet add package Nethereum.Web3

또는 패키지 관리자 콘솔을 통해:

Install-Package Nethereum.Web3

빠른 시작

X-API-Key 헤더를 사용하여 256 Blocks에 연결하세요:

using Nethereum.Web3;
using Nethereum.JsonRpc.Client;
using System.Net.Http;
 
// Create HttpClient with API key header
var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Add("X-API-Key", "your-api-key");
 
// Create RPC client with custom HttpClient
var rpcClient = new RpcClient(
    new Uri("https://rpc.256blocks.com/ethereum"),
    httpClient
);
 
// Create Web3 instance
var web3 = new Web3(rpcClient);
 
// Get the latest block number
var blockNumber = await web3.Eth.Blocks.GetBlockNumber.SendRequestAsync();
Console.WriteLine($"Latest Block: {blockNumber.Value}");

계정 잔액 조회

using Nethereum.Web3;
using Nethereum.JsonRpc.Client;
using System.Net.Http;
 
var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Add("X-API-Key", "your-api-key");
 
var rpcClient = new RpcClient(
    new Uri("https://rpc.256blocks.com/ethereum"),
    httpClient
);
 
var web3 = new Web3(rpcClient);
 
// Get account balance
var address = "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb";
var balance = await web3.Eth.GetBalance.SendRequestAsync(address);
var etherAmount = Web3.Convert.FromWei(balance.Value);
 
Console.WriteLine($"Balance: {etherAmount} ETH");

컨트랙트 데이터 조회

using Nethereum.Web3;
using Nethereum.JsonRpc.Client;
using Nethereum.ABI.FunctionEncoding.Attributes;
using Nethereum.Contracts;
using System.Numerics;
using System.Net.Http;
 
// ERC-20 balanceOf function
[Function("balanceOf", "uint256")]
public class BalanceOfFunction : FunctionMessage
{
    [Parameter("address", "account", 1)]
    public string Account { get; set; }
}
 
var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Add("X-API-Key", "your-api-key");
 
var rpcClient = new RpcClient(
    new Uri("https://rpc.256blocks.com/ethereum"),
    httpClient
);
 
var web3 = new Web3(rpcClient);
 
// USDC contract on Ethereum
var contractAddress = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48";
var contract = web3.Eth.GetContractHandler(contractAddress);
 
var balanceOfMessage = new BalanceOfFunction
{
    Account = "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb"
};
 
var balance = await contract.QueryAsync<BalanceOfFunction, BigInteger>(balanceOfMessage);
Console.WriteLine($"USDC Balance: {balance}");

멀티체인 지원

엔드포인트를 변경하여 다른 체인에 연결하세요:

// Ethereum Mainnet
var ethClient = new RpcClient(new Uri("https://rpc.256blocks.com/ethereum"), httpClient);
 
// Base
var baseClient = new RpcClient(new Uri("https://rpc.256blocks.com/base"), httpClient);
 
// Arbitrum
var arbClient = new RpcClient(new Uri("https://rpc.256blocks.com/arbitrum"), httpClient);
 
// Polygon
var polygonClient = new RpcClient(new Uri("https://rpc.256blocks.com/polygon"), httpClient);

리소스

Nethereum | 256 Blocks