Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How parse dict from cell ? #29

Open
markdrrr opened this issue Mar 3, 2024 · 2 comments
Open

How parse dict from cell ? #29

markdrrr opened this issue Mar 3, 2024 · 2 comments

Comments

@markdrrr
Copy link

markdrrr commented Mar 3, 2024

I call get method in contract
my code:

const endpoint = await getHttpEndpoint({
    network: "testnet",
});
const client = new TonClient({ endpoint });
const contract = Address.parse('kQC............Ze');
const data = await client.callGetMethod(contract, 'get_data')
const result = data .stack.readCell()

contract code:

get fun data() : map<Address, Int> {
   return self.data;
}

how to get a dictionary of data in js from a contract ?

@pavel-rakhmanov
Copy link

Try this:

const dict = result.stack
  .readCell()
  .asSlice()
  .loadDictDirect(Dictionary.Keys.Uint(8), Dictionary.Values.Cell());

for (const key of dict.keys()) {
  const cell = dict.get(key);
  
  // process cell here
}

@pbxr250
Copy link

pbxr250 commented Oct 13, 2024

In case values are in slice (string):

...
.loadDictDirect(Dictionary.Keys.Uint(8), Dictionary.Values.Buffer(num)); // number of bytes (symbols in string)

for (const key of dict.keys()) {
 const string= dict.get(key);
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants