Coder Social home page Coder Social logo

tonlib.net's People

Contributors

justdmitry avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

tonlib.net's Issues

Example on how to deserialize to TEP64 dictionary.

Hello! Thank you for your excellent library.

I'm trying to pull Jetton Master data, I am using the reference specification to assist me: https://github.com/ton-blockchain/TEPs/blob/master/text/0064-token-data-standard.md#specification

I have the following example:

First, I pull the get_jetton_data:

Info smcRouter = await _ton.TrySmcLoad(Address);
var result = await _ton.SmcRunGetMethod(smcRouter.Id, new MethodIdName("get_jetton_data"));

var stack = result.Stack.ToArray();

var totalSupply = stack[0].ToBigInteger();
var mintable = stack[1].ToBigInteger();
var adminAddress = stack[2].GetAddress();
var metadataCell = stack[3].ToBoc().RootCells[0];

Then, I want to deserialize the metadata cell to it's components, however I'm struggling to see how to do this.

Initially I want to decompose it to first grab the Decimals, where the case is there are onchain properties for, I am using this jUSDT token to test this:

https://tonscan.com/EQBynBO23ywHy_CgarY9NK9FTz0yDsG82PtcbSTQgGoXwiuA?tab=methods

This reports the following for jetton_content:

{
  "type": "onchain",
  "data": {
    "image": "https://bridge.ton.org/token/1/0xdac17f958d2ee523a2206206994597c13d831ec7.png",
    "uri": "https://bridge.ton.org/token/1/0xdac17f958d2ee523a2206206994597c13d831ec7.json",
    "decimals": "6"
  }
}

Now I want to deserialize my metadataCell into a dictionary for me to extract the above representation, but I can't see how to do this. I can call LoadDict on the cell, which it should be, I get back a Cell.
I then use the specification referenced for Token Data, that the key should be a SHA256 as a string, and the value should be serialized later (so I pull the Slice). This isn't working for me and fails to deserialize the dictionary (No dictionary found).

public static Metadata ParseFromCell(Cell cell)
{
    const int OnchainContent = 0;
    const int OffchainContent = 1;

    var slice = cell.BeginRead();
    var contentType = slice.LoadByte();

    if(contentType != OnchainContent)
        throw new Exception("Unsupported representation type");

    var dict = slice.LoadDict();
    var output = dict.BeginRead().LoadAndParseDict<string, TonLibDotNet.Cells.Slice>(
        256,
        x => x.LoadString()!,
        x => x,
        new StringComparer());

    return new Metadata();
}

Do you have any suggestions on how I can get this deserialized correctly, or at least get a reference to a Dictionary<TKey,TValue> for me to take this further?

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.