Skip to content

terentev-space/NBitcoin.Sugarchain

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NBitcoin.Sugarchain

Latest Version Software License NuGet downloads Size

🚧 Attention: the project is currently under development! 🚧

⚠️Disclaimer: I am not an expert in cryptocurrencies, there may be errors in logic and use, but I did not find any ready-made solutions for Sugarchain and decided to write my own. What i wanted to say: use carefully, do not trust me!


Sugarchain project website: https://sugarchain.org/
Sugarchain API: https://api.sugarchain.org/


NBitcoin repository (Github): https://github.com/MetacoSA/NBitcoin
SugarchainApiClient repository (Github): https://github.com/terentev-space/SugarchainApiClient

Install

PM

Install-Package NBitcoin.Sugarchain

.NET CLI

dotnet add package NBitcoin.Sugarchain

NuGet

NBitcoin.Sugarchain

Examples

🔶 Public & Private Keys / Addresses & Wallets

Init

Network network = Sugarchain.Instance.Mainnet;
SugarFactory factory = SugarFactory.Instance(network);

Create new "wallet"

SugarSecret newSugar = factory.CreateSecret();

// Output (Keys are real but empty):
Console.WriteLine(newSugar.GetPublicSugarAddress());  // sugar1qkhcx7tf5jc7xdnas70tvasxxvh3aec2586llq2
Console.WriteLine(newSugar.GetPublicLegacyAddress()); // OP_DUP OP_HASH160 b5f06f2d34963c66cfb0f3d6cec0c665e3dce154 OP_EQUALVERIFY OP_CHECKSIG
Console.WriteLine(newSugar.GetPrivateKey());          // KzTdaJrKvT9DKHxvHVhBPX7rM6BJvBMVne2w1rEigorySynB2wFs

Import "wallet"

string privateKey;// WIF
privateKey = "KzTdaJrKvT9DKHxvHVhBPX7rM6BJvBMVne2w1rEigorySynB2wFs";
/* OR */
privateKey = newSugar.GetPrivateKey();

// newSugar ≈ parsedSugar
SugarSecret parsedSugar = factory.ParseSecret(privateKey);

// Output (Keys are real but empty):
Console.WriteLine(parsedSugar.GetPublicSugarAddress());  // sugar1qkhcx7tf5jc7xdnas70tvasxxvh3aec2586llq2
Console.WriteLine(parsedSugar.GetPublicLegacyAddress()); // OP_DUP OP_HASH160 b5f06f2d34963c66cfb0f3d6cec0c665e3dce154 OP_EQUALVERIFY OP_CHECKSIG
Console.WriteLine(parsedSugar.GetPrivateKey());          // KzTdaJrKvT9DKHxvHVhBPX7rM6BJvBMVne2w1rEigorySynB2wFs

Import "wallet" public address

string address;
address = "sugar1qkhcx7tf5jc7xdnas70tvasxxvh3aec2586llq2";
/* OR */
address = newSugar.GetPublicSugarAddress();
/* OR */
address = parsedSugar.GetPublicSugarAddress();

SugarKey parsedAddress = factory.ParsePublic(address);

// Output (Keys are real but empty):
Console.WriteLine(parsedAddress.GetPublicSugarAddress());  // sugar1qkhcx7tf5jc7xdnas70tvasxxvh3aec2586llq2
Console.WriteLine(parsedAddress.GetPublicLegacyAddress()); // 0 b5f06f2d34963c66cfb0f3d6cec0c665e3dce154

🔶 Transaction

Network network = Sugarchain.Instance.Mainnet;
SugarFactory factory = SugarFactory.Instance(network);

SugarSecret from = factory.ParseSecret("KzTdaJrKvT9DKHxvHVhBPX7rM6BJvBMVne2w1rEigorySynB2wFs");
SugarKey to = factory.ParsePublic("sugar1qmqvkrn5zw2v60tl0syfmxwrkre4kagpak0t9s5");

Response<IReadOnlyList<UnspentResult>> unspentResponse = client.Api.Unspent(from);

decemal amount = 0.1m;
decemal fee = 0.00001001m;

Transaction transaction = TransactionFactory.Instance(network).Create(
                                from: from,
                                to: to,
                                amount: amount,
                                fee: fee,
                                unspent: unspentResponse.Result,
                                sign: true
                            );
                            
string raw = transaction.ToHex();

Response<string> response;
response = client.Api.Broadcast(transaction);// OR await client.Api.BroadcastAsync(transaction)
/* OR */
response = client.Api.Broadcast(raw);// OR await client.Api.BroadcastAsync(raw)

Credits

License

The Apache 2.0 License (Apache-2.0). Please see License File for more information.

About

Sugarchain extensions for NBitcoin & SugarchainApiClient

Topics

Resources

License

Stars

Watchers

Forks

Languages