using System.Threading.Tasks;
using Netezos.Forging.Models;
public static async Task Main()
using var rpc = new TezosRpc("https://rpc.tzkt.io/florencenobanet/");
var key = Key.FromBase58("edsk3JJe787xdYDkSir5Uvozjc1VQnZsZJpVra1YsqYx8hjnShdi1G");
var head = await rpc.Blocks.Head.Hash.GetAsync<string>();
var counter = await rpc.Blocks.Head.Context.Contracts[key.PubKey.Address].Counter.GetAsync<int>();
for (int i = 0; i < 3; i++)
Source = key.PubKey.Address,
Amount = 100000 * (i + 1),
Destination = "tz1KhnTgwoRRALBX6vRHRnydDGSBFsWtcJxc",
var dryRun = await rpc.Blocks.Head.Helpers.Scripts.RunOperation.PostAsync<JsonDocument>(ops);
foreach (var content in dryRun.RootElement.RequiredArray("contents").EnumerateArray())
var expectedOperationStatus =
content.Required("metadata").Required("operation_result").RequiredString("status");
if (expectedOperationStatus != "applied")
throw new InvalidOperationException($"Transaction cannot be applied : {dryRun.ToJsonString()}");
var bytes = await new LocalForge().ForgeOperationGroupAsync(head, ops);
byte[] signature = key.SignOperation(bytes);
var result = await rpc.Inject.Operation.PostAsync(bytes.Concat(signature));
Console.WriteLine((string)result);
public static class JsonExtensions
public static JsonElement RequiredArray(this JsonElement el, string name)
return el.TryGetProperty(name, out var res) && res.ValueKind == JsonValueKind.Array ? res
: throw new Exception($"Missed required array {name}");
public static string RequiredString(this JsonElement el, string name)
return el.TryGetProperty(name, out var res) && res.ValueKind == JsonValueKind.String ? res.GetString()
: throw new Exception($"Missed required string {name}");
public static JsonElement Required(this JsonElement el, string name)
return el.TryGetProperty(name, out var res) ? res
: throw new Exception($"Missed required property {name}");
public static string ToJsonString(this JsonDocument jdoc)
using var stream = new MemoryStream();
var writer = new Utf8JsonWriter(stream, new JsonWriterOptions { Indented = true });
return Encoding.UTF8.GetString(stream.ToArray());
public static string ToJsonString(this JsonElement el)
using var stream = new MemoryStream();
var writer = new Utf8JsonWriter(stream, new JsonWriterOptions { Indented = true });
return Encoding.UTF8.GetString(stream.ToArray());