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 one smart contract on TON Blockchain call a method on another smart contract?

There's an existing contract that was deployed by somebody else, for example a token, that has getter methods like get_balance(address) or get_total_supply()

I'm writing a new smart contract in FunC that needs to read information from this token contract, for example, I need to read somebody's balance from my code

How can I do it?

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

Answers


It is not possible for one contract on TON to call a method on another smart contract on TON.

The pattern of contracts calling contracts synchronously (within the flow of the same transaction) originates from Solidity and the EVM but this pattern is not applicable to all blockchains. There are several conceptual differences between TON and the EVM - you can read more about them here.

It is better to view smart contracts on TON like micro services that are running on different machines. They can send messages to each other but these messages are asynchronous and not atomic - so they may be handled in different blocks (on different transactions).

You will need to accommodate for this in your contract architecture. Here are some ideas on how to do this:

  1. Let's say your contract needs to know its own token balance. You can store this balance on a variable in your own contract. Every time your token wallet receives tokens, you may be able to arrange to have a notification message sent to you, and update this variable when this message is received.

  2. To query data from a different contract, you can send it a message and have the other contract reply with a message containing the response. This will break the flow into 3 different transactions, which will bring its own complexities, like undoing any effects of the first if one of the later ones fail.

1
1
Posted 2 years ago
Tal Kol
359 × 3 Administrator
  
  

Damn, you answered your own question.

Brave   one year ago Report
  
  

It only partially answers the question, which is quite simple. How can a contract get the balance of a token for an address?

Yakitori   6 months ago Report