Examples: query, "exact match", wildcard*, wild?ard, wild*rd
Fuzzy search: cake~ (finds cakes, bake)
Term boost: "red velvet"^4, chocolate^2
Field grouping: tags:(+work -"fun-stuff")
Escape special characters +-&|!(){}[]^"~*?:\ - e.g. \+ \* \!
Range search: properties.timestamp:[1587729413488 TO *] (inclusive), properties.title:{A TO Z}(excluding A and Z)
Combinations: chocolate AND vanilla, chocolate OR vanilla, (chocolate OR vanilla) NOT "vanilla pudding"
Field search: properties.title:"The Title" AND text
Answered
How can you debug a TON smart contract in FunC and print logs or dump variables?

I'm developing a smart contract for TON blockchain in FunC and I'm trying to find a bug in my code. I'm trying to debug the issue and will appreciate something like console.log() from JavaScript so I can add prints / logs in strategic places and understand what's going on. Can this be done?

7
7
Posted 2 years ago
Tal Kol
359 × 3 Administrator
Votes Newest

Answers 2


The TVM has a special function for dumping variables in debug - ~dump

Run ~dump(variable_name); to print a variable's contents.

Run ~dump(12345); to print the number 12345.

Example:

() recv_internal(int msg_value, cell in_msg, slice in_msg_body) impure {

  ;; let's say I want to print the value of the variable msg_value
  
  ~dump(msg_value);
}

Please note that this command will not run on mainnet, so do not deploy production contracts with it. My favorite way to test smart contracts locally is using ton-contract-executor - this awesome library run a local version of the TVM in web-assembly right inside Node.js, which is very convenient for writing JavaScript/TypeScript tests.

To enable debug prints in ton-contract-executor, when you create your contract instance pass debug: true in SmartContractConfig and print the logs after interacting with the contract:

import { SmartContract } from "ton-contract-executor";

const contract = await SmartContract.fromCell(codeCell, dataCell, {
  debug: true // enable debug
});

const send = await contract.sendInternalMessage(...);

console.log(send.logs); // print the logs
6
6
Posted 2 years ago
Edited 2 years ago
Tal Kol
359 × 3 Administrator

Get +971528536119 100% safe and effective abortion pills in UAE (Dubai, Abu Dhabi, Sharjah, Al Ain, Ajman, RAK City, Fujairah) from Dr. Hamad. Contact us at +971528536119 On Whatsapp for Mifepristone and Misoprosto

  
  
Posted 6 months ago
  
  

o get started, simply navigate to the "Ask question" page and ask a question. You can also help people by answering their questions and you will get reputation points. https://www.escortdirectory.info/escort/india/chandigarh/

Sapana   26 days ago Report
24K Views
2 Answers
2 years ago
26 days ago
Tags