This repository has been archived by the owner on Jan 7, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Usage
darkfriend77 edited this page Jul 31, 2021
·
2 revisions
var WEBSOCKETURL = "wss://xyz.node.com"; // or local node ws://127.0.0.1:9944
using var client = new SubstrateClient(new Uri(WEBSOCKETURL));
await client.ConnectAsync(cancellationToken);
// MetaData
Console.WriteLine(client.MetaData.Serialize());
// [Plain] Value: T::AccountId (from metaData)
var reqResult = await client.GetStorageAsync("Sudo", "Key", cancellationToken);
Console.WriteLine($"RESPONSE: '{reqResult}' [{reqResult.GetType().Name}]");
RESPONSE: '"5DotMog6fcsVhMPqniyopz5sEJ5SMhHpz7ymgubr56gDxXwH"' [AccountId]
// [Map] Key: T::AccountId, Hasher: Blake2_128Concat, Value: AccountInfo<T::Index, T::AccountData> (from metaData)
var reqResult = await client.GetStorageAsync("System", "Account", new [] {Utils.Bytes2HexString(Utils.GetPublicKeyFrom(address))}, cancellationToken);
Console.WriteLine($"RESPONSE: '{reqResult}' [{reqResult.GetType().Name}]");
RESPONSE: '{"Nonce":{"Value":15},"Consumers":{"Value":0},"Providers":{"Value":1},"AccountData":{"Free":{"Value":1998766600579252800594},"Reserved":{"Value":0},"MiscFrozen":{"Value":0},"FeeFrozen":{"Value":0}}}' [AccountInfo]
var systemName = await client.System.NameAsync(cancellationToken);
RESPONSE: 'DOTMog Node' [String]
// Dest: <T::Lookup as StaticLookup>::Source, Value: Compact<T::Balance>
var balanceTransfer = ExtrinsicCall.BalanceTransfer("5DotMog6fcsVhMPqniyopz5sEJ5SMhHpz7ymgubr56gDxXwH", BigInteger.Parse("100000000000"));
var reqResult = await client.Author.SubmitExtrinsicAsync(balanceTransfer, accountZurich, 0, 64, cancellationToken);
RESPONSE: '"0xB1435DA6A0F2C9C00E1AC0FAD7EBD2515B8AACDA12F27384A2148C556FEE627A"' [Hash]
// create a call back action with the expected type
Action<ExtrinsicStatus> actionExtrinsicUpdate = (extrinsicUpdate) => Console.WriteLine($"CallBack: {extrinsicUpdate}");
// create the extrinsic parameters
var balanceTransfer = ExtrinsicCall.BalanceTransfer("5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY", 1000);
// submit and subscribe to the extrinsic
var subscriptionId = await client.Author.SubmitAndWatchExtrinsicAsync(actionExtrinsicUpdate, balanceTransfer, accountDMOG_GALxeh, 0, 64, cancellationToken);
// wait for extrinsic pass into a finalized block
Thread.Sleep(60000);
// unsubscribe
var reqResult = await client.Author.UnwatchExtrinsicAsync(subscriptionId, cancellationToken);
This API is being developed and maintained by the BloGa Tech AG (Switzerland) and is part of Open Grants Program of the Web3 Foundation.