What are Best Practices to debug smart contract?

For example I deploy smartcontract to testnet, but something wrong and ton bounce back.

Code is huge, and i dont know where to start debugging.

Can I start local node and read logs, or stdout or something?

Jul 11, 2022, 10:28 AM
I advice you this! https://github.com/Naltox/ton-contract-executor
It allows you to query public smart contracts and execute stuff locally
Jul 11, 2022, 10:30 AM
The best practice is to use ton-contract-executor. If you're familiar with Solidity, this is very similar to what hardhat does. It runs the TVM in Javascript so your tests are very fast and 100% free.

This project shows a working setup for this on a simple contract: https://github.com/ton-defi-org/tonstarter-contracts

You can enable debug mode in ton-contract-executor and then you can add DEBUG prints from inside your FunC code, here is an example: https://github.com/ton-defi-org/tonstarter-contracts/blob/main/contracts/main.fc#L57
Going another step through a contract is not a problem, it's a feature. It makes the system modular and separates the wallet authentication concern (single signer vs multi-sig for example) from the dapp concerns. If Ethereum had made a similar decision you would be able to see people using multi-sig wallets for defi apps there.. which is a big headache currently
Jul 11, 2022, 10:59 AM
I was confused by some repositories like

https://github.com/ton-blockchain/func-contest1-tests/blob/master/tests/tests/tests-1.fc

and this šŸ˜…
https://github.com/raiym/astonished/blob/master/smartcontract/test/lottery-test-suite.fif

But i found
https://github.com/ton-defi-org/tonstarter-contracts/blob/main/test/deposit.spec.ts

And it is js-spec-hardhat style, that great news, thanks šŸ˜ŒšŸ˜Œ
Jul 11, 2022, 11:32 AM
These are similar to writing your tests in Solidity. I know that many people tried this years ago on Ethereum and everybody concluded itā€™s not a good idea and nobody does it today
I donā€™t think we need to reinvent the wheel here, there are established practices for effective smart contract development and those include writing tests in JavaScript. This is by far the most effective and efficient method
Jul 11, 2022, 11:53 AM
In tonweb what is send mode?
Jul 11, 2022, 1:46 PM
FunC is a difficult sandboxed language due to security concerns of managing money on-chain. Much like Solidity. I would only use it to write the code that runs on-chain (the contract itself). Peripherals like a test suite can run anywhere, why would I use the most difficult secure language to write them? JavaScript is by far the easiest most popular language in the world, itā€™s a natural choice for anything that doesnā€™t run on-chain.

And regarding Fift, I think you can safely ignore its existence altogether. I havenā€™t seen one relevant use-case so far that justifies the time it takes to learn it. You simply donā€™t need it for anything.

The straightforward stack is very simple:

On-chain code - FunC

Everything else (test suites, build and deploy scripts, client apps, telegram bots, backends) - TypeScript
Jul 11, 2022, 3:03 PM
> You simply donā€™t need it for anything.

I don't thinks so. I could develop native blockchian indexer (in c++ ton sources) only because I've learned Fift before. In my opinion - fift is good for quick experiments and understanding the work of TON.

Toncli helps using fift for interacting with blockchain for parsing and fast MVP developing.

> The straightforward stack is very simple:

Don't think so. Using tonlibjson you can interact with TVM / TON stuff in any language. So actually you can use any language you want. (Go, Python, Etc.)

Also tests can be written on Func itself https://github.com/disintar/toncli/blob/master/docs/advanced/func_tests_new.md it's very simple with new version of toncli & new tests engine.
Would we be able to run @disintar faster without fift & toncli and using typescript?

Maybe.

Would it be just as fun, cool and educational?

Unlikely.
Jul 11, 2022, 3:22 PM
Will be cooler and more fun šŸ˜‚
Of course you can use any language.. the question what is the most effective. There is soooo much to learn. We donā€™t need to overkill people with learning things that arenā€™t a must.

You want your teams to focus on learning 2 environments well and reuse this knowledge for multiple products. You will be able to ship faster in higher quality.

Youā€™re not going to build your client in Python. And if you already know a good testing framework on JavaScript might as well reuse it for other parts.

I actually think itā€™s much more educational too. So people can focus on the important things and not on boilerplate :)
Jul 11, 2022, 3:26 PM
In the current scenario, typescript is a very complex setup, the improvement of which will greatly slow down "growth".

Fift is much closer to the TON sources and allows you to experiment and introduce improvements faster.

The improvement of TON is much easier through the improvement of fift than through typescript, which has a very distant relationship to the TON sources.

Show me the contributing activity to the TON sources from your typescripters? If you look at the core TON repo improvement, you will see that these people are using fift.

So I would be careful with the choice of "important things"
Jul 11, 2022, 3:32 PM
I think if the core people would switch to improving infra like ton-contract-executor and improving the TypeScript stack, it would do much good to the ecosystem
TypeScript is no longer a complex setup, you have starter projects already set up
Jul 11, 2022, 3:35 PM
I don't think so. Fift is very close to the TON sources and allows you to understand them more accurately, as well as quickly make improvements.

Whereas ton-contract-executor is a very far thing from the sources, although it is really good.
Jul 11, 2022, 3:36 PM
Normally you donā€™t want your app developers working in the opcode/bytecode level. We have abstractions for a reason
But of course there is no right answer, itā€™s all a question of personal taste ā¤ļøā¤ļø
Here is a relatively complex multi-contract AMM with client and contracts and bot, with the stack I believe in, without toncli and without fift: https://github.com/tonswap

When we finish improving ton-contract-executor and wrapping it like hardhat, unify the api between tonweb and ton npm, this will be so elegant you could eat off of it :)
Jul 11, 2022, 3:43 PM
idk

just 2 tests counter smart contract

on js mocha spec

https://github.com/ton-defi-org/tonstarter-contracts/blob/main/test/counter.spec.ts

and counter test on func

https://github.com/ton-blockchain/func-contest1-tests/blob/master/tests/tests/tests-1.fc

any js, ruby, python, hardhat, truffle, anchor coder knows how read and write specs without reading documentation
Jul 11, 2022, 3:45 PM
why did you make a dex that support trades only for ton/token pairs?
Jul 11, 2022, 3:46 PM
Good question, itā€™s the correct first version IMO:

1. Jettons are sharded to multi contracts so Jetton to Jetton swaps create too many messages that become hard to reason about. I believe smart contracts need to be kept simple so people could review and understand them. TON coin is native so you can handle it without extra messages so it simplifies the flow.

2. Liquidity pairs for the benefit of the ecosystem should be encouraged to be paired with TON coin to increase demand for TON coin. Itā€™s much better for us than people doing pairs with USDC for example.

3. Most popular pairs on Uniswap de-facto pair with ETH.

4. You can swap between any two tokens with multi hop. And thereā€™s going to be less price impact if we concentrate liquidity in the main pairs with TON and always go through them.
It wasnā€™t done out of laziness :)
Jul 11, 2022, 3:52 PM
ahahah
understood, still native-token pairs feels like uniswap v1
Jul 11, 2022, 3:53 PM
The client will support swapping any two tokens, donā€™t worry. The pairs are an implementation detail of how we split liquidity internally
Jul 11, 2022, 3:53 PM
+ jetton-to-jetton are pretty easy to do
Jul 11, 2022, 3:53 PM
Yea, TON blockchain is very different from Ethereum that runs everything atomically. Less messages is better IMO
Jul 11, 2022, 3:53 PM
i have a different opinion, 9 messages is not such a big number
Jul 11, 2022, 3:54 PM
Hard to understand
Less chance for security vulnerabilities
Jul 11, 2022, 3:55 PM
even if there are more messages the logic is still the same
Jul 11, 2022, 3:55 PM
If I understand well, 9 messages means that the swap would take at least 9 different blocks ?
Jul 11, 2022, 3:55 PM
Yes
Jul 11, 2022, 3:55 PM
no
Jul 11, 2022, 3:55 PM
And you need to explore 9 different pages in a block explorer to understand what happened
Messages are asynchronous, you canā€™t assume they will be handled in the same block
Jul 11, 2022, 3:56 PM
but i cant assume it will be handled in different block, too
Jul 11, 2022, 3:56 PM
Your code should assume that to avoid vulnerabilities, thatā€™s what I meant
Jul 11, 2022, 3:57 PM
yes it make sense, really
im also totally for the kiss logic
Jul 11, 2022, 3:57 PM
ok so in minimum 1 block and in an unknown max of blocks šŸ‘
Jul 11, 2022, 3:57 PM
Also I think concentrating liquidity will be better for price impact
Max 9 different but you donā€™t know when
Jul 11, 2022, 3:58 PM
well soon you will be able to test our dex, so feel free to write your opinion
Jul 11, 2022, 3:59 PM
šŸ‘šŸ‘šŸ‘
We can audit each other
Jul 11, 2022, 4:00 PM
9 messages for one swap?
Jul 11, 2022, 4:01 PM
(Sorry)
Jul 11, 2022, 4:03 PM
mandatory for jetton-to-jetton pairs
Jul 11, 2022, 4:04 PM
I have a jetton-to-jetton contract but it uses less than 9 messages
Jul 11, 2022, 4:06 PM
@dariolol how are you doing tests? are you open source?
Jul 11, 2022, 4:07 PM
ts and ton-executor, for now its close source
Jul 11, 2022, 4:17 PM
I hope you will open source before release
Jul 11, 2022, 4:28 PM
What's the easiest way to run a lite client and retrieving basic info from blockchain?
Some great library or smth
Jul 11, 2022, 4:41 PM
If you deploy a "dex" contract manually for each pair with an init method, it could be reduced. If you make something like uniswap and so on, you need more transactions
Jul 11, 2022, 4:45 PM
https://github.com/xssnick/tonutils-go if you like golang
Jul 11, 2022, 4:46 PM
Thx for direction! Is there something on node or python?
Jul 11, 2022, 4:46 PM
Yes, tonweb for example, on js
But i think it uses api to interact with ton
Jul 11, 2022, 4:48 PM
yes it uses https://toncenter.com/api/v2/jsonRPC :(
Jul 11, 2022, 4:49 PM
Havenā€™t used any of them but maybe:

https://github.com/toncenter/ton-http-api

https://github.com/toncenter/pytonlib
Maybe these will be helpful too:

https://github.com/ton-foundation/ton-api-v4

https://github.com/ton-foundation/ton-lite-client
Everscale code is assume is their weird solidity thing? Or is it FunC?
Jul 11, 2022, 5:08 PM
It uses the same logic as func
The only weird thing they added is await
Jul 11, 2022, 5:08 PM
Well, with await everything is easy šŸ™ƒ
Jul 11, 2022, 5:08 PM
The problem is the hardencoded value for gas usage by the contract
Thats why a dex shouldn't use native ton, since gas price could change
You should read network config and use that to compute a dynamic value for the gas usage
Jul 11, 2022, 5:24 PM
need to hardencode the value of gas, not the value of TON required to pay for gas
Jul 11, 2022, 5:40 PM
Pytonlib gives me this error on client.init(). Is it a common issue?
Jul 11, 2022, 6:07 PM
Hi, maybe you use old version? Try to pip3 install -U pytonlib
Jul 11, 2022, 7:08 PM
It works great on ubuntu but not on windows. I'm investigating more
Jul 11, 2022, 7:09 PM
One more problem could be in Windows PATH max length. This path seems long enough. Did you extended PATH max length when installing python (there was a checkbox in an installer)?
Jul 11, 2022, 7:11 PM
maybe better use WSL
Jul 11, 2022, 7:11 PM
Or Docker with Ubuntu
Jul 11, 2022, 9:00 PM
I used wsl thx. Temporary solution tho
Jul 11, 2022, 9:47 PM
Btw, it would be good to get some tech details on this issue to solve the problem in the library
Jul 11, 2022, 9:56 PM
I'll open an issue later
Jul 11, 2022, 9:59 PM
Thx a lot!
Hello once again. Did you installed OpenSSL for win64? If not, then could you please try to install it. Here is the instruction: https://github.com/toncenter/ton-http-api#local-run-experimental
A missing library is included in FileNotFound error in windows and itā€™s the most unclear error which took a lot of time to mešŸ˜…
Jul 12, 2022, 6:39 PM
Thing is I checked that file directory and the file actually was there. Anyway i'm reinstalling openssl and i'll let you know
Jul 12, 2022, 6:45 PM
The previous time I forgot about this thing. Hope it will work
Note, that the 1.1.1 version is required. With 3.0 it wonā€™t workšŸ™ƒ
Jul 12, 2022, 6:47 PM
Probably that's what happened. Now it works. I probably installed another ver by mistake
Sry for wasting ur time
Jul 12, 2022, 6:50 PM
No problem, glad to help!šŸ™‚
Jul 12, 2022, 6:51 PM

Ā© 2024 Draquery.com All rights reserved.