Giter Club home page Giter Club logo

tonsdk.net's Introduction

TonSdk.NET

You can ask questions that may arise during the use of the SDK in our Telegram group.

Packages

NuGet NuGet
Core library with types and structures for TON Blockchain

NuGet NuGet
RPC Client for work with TonCenter API

NuGet NuGet
Abstractions for work with smart contracts in TON Blockchain

NuGet NuGet
Library to work with Ton Connect 2.0

NuGet NuGet
Library to work with Ton ADNL

Features and status

  • Builder, Cell, Slice
  • BOC (de)serialization
  • Hashmap(E) (dictionary) (de)serialization
  • Mnemonic BIP39 standard
  • Mnemonic TON standard
  • Coins (class for TON, JETTON, e.t.c.)
  • Address (class for TON address)
  • Message layouts (such as MessageX e.t.c.)
  • RPC client
  • Popular structures from block.tlb
  • Contracts (abstract TON contract class)
  • Ed25519 signing of transactions
  • ~100% tests coverage

Overview example

// Create a new instance of the TonClient using the specified endpoint and API key
TonClient tonclient = new TonClient(new TonClientParameters { Endpoint = "https://toncenter.com/api/v2/jsonRPC", ApiKey = "xxx" });

// Generate a new mnemonic phrase
Mnemonic mnemonic = new Mnemonic();

// Create a new preprocessed wallet using the public key from the generated mnemonic
PreprocessedV2 wallet = new PreprocessedV2(new PreprocessedV2Options { PublicKey = mnemonic.Keys.PublicKey! });

// Get the address associated with the wallet
Address address = wallet.Address;

// Convert the address to a non-bounceable format
string nonBounceableAddress = address.ToString(AddressType.Base64, new AddressStringifyOptions(false, false, true));

// Retrieve the wallet data
Cell? walletData = (await tonclient.GetAddressInformation(address)).Data;

// Extract the sequence number from the wallet data, or set it to 0 if the data is null
uint seqno = walletData == null ? 0 : wallet.ParseStorage(walletData.Parse()).Seqno;

// Get the balance of the wallet
Coins walletBalance = await tonclient.GetBalance(address);

// Get the destination address for the transfer from the Ton DNS
Address destination = await tonclient.Dns.GetWalletAddress("foundation.ton");

// Create a transfer message for the wallet
ExternalInMessage message = wallet.CreateTransferMessage(new[]
{
    new WalletTransfer
    {
        Message = new InternalMessage(new()
        {
            Info = new IntMsgInfo(new()
            {
                Dest = destination,
                Value = new Coins("0.2")
            }),
            Body = new CellBuilder().StoreUInt(0, 32).StoreString("test").Build()
        }),
        Mode = 1
    }
}, seqno).Sign(mnemonic.Keys.PrivateKey, true);

// Send the serialized message
await tonclient.SendBoc(message.Cell!);

Overview example (Jetton Transfer)

// Define the address of the jetton master contract
Address jettonMasterContract = new Address("EQBlHnYC0Uk13_WBK4PN-qjB2TiiXixYDTe7EjX17-IV-0eF");

// Get the jetton wallet address
Address jettonWallet = await tonclient.Jetton.GetWalletAddress(jettonMasterContract, address);

// Create a message body for the jetton transfer
Cell jettonTransfer = JettonWallet.CreateTransferRequest(new() { Amount = new Coins(100), Destination = destination });

// Create a transfer message for the wallet
ExternalInMessage message = wallet.CreateTransferMessage(new[]
{
    new WalletTransfer
    {
        Message = new InternalMessage(new()
        {
            Info = new IntMsgInfo(new()
            {
                Dest = jettonWallet,
                Value = new Coins("0.1")
            }),
            Body = jettonTransfer
        }),
        Mode = 1
    }
}, seqno).Sign(mnemonic.Keys.PrivateKey, true);

// Pre-calculate fee before sending message
EstimateFeeResult fees = await _client.EstimateFee(message);

// Send the serialized message
await tonclient.SendBoc(message.Cell!);

Donation

continuation.ton

License

MIT License

tonsdk.net's People

Contributors

purpleguy99 avatar pyandr3w avatar artmon avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.