Skip to content
This repository was archived by the owner on Dec 12, 2024. It is now read-only.

feat: describe how to obtain config params #245

Merged
merged 2 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pages/book/config.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ In [Blueprint][bp], they act as default unless modified in `wrappers/ContractNam

`false{:json}` by default.

If set to `true{:json}`, enables debug output of a contract and allows usage of [`dump(){:tact}`](/ref/api-debug#dump) function, which is useful for [debugging purposes](/book/debug). With this option enabled, the contract will report that it was compiled in debug mode using the `supported_interfaces` method.
If set to `true{:json}`, enables debug output of a contract and allows usage of [`dump(){:tact}`](/ref/core-debug#dump) function, which is useful for [debugging purposes](/book/debug). With this option enabled, the contract will report that it was compiled in debug mode using the `supported_interfaces` method.

```json filename="tact.config.json" {8,14}
{
Expand Down
2 changes: 1 addition & 1 deletion pages/book/expressions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ Tact strings support a range of [escape sequences](https://en.wikipedia.org/wiki

Read more about strings and [`String{:tact}`][p] type:\
[Primitive types in the Book][p]\
[Strings and StringBuilders in the Reference](/ref/api-strings)
[Strings and StringBuilders in the Reference](/ref/core-strings)

</Callout>

Expand Down
2 changes: 1 addition & 1 deletion pages/book/integers.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Use underscores (`_`) to improve readability: $\mathrm{0b111\_111\_111}$ is equa

For example, arithmetic with dollars requires two decimal places after the dot — those are used for the cents value. But how would we represent the number \$$1.25$ if we're only able to work with integers? The solution is to work with _cents_ directly. This way, \$$1.25$ becomes $125$ cents. We simply memorize that the two rightmost digits represent the numbers after the decimal point.

Similarly, working with Toncoins requires nine decimal places instead of the two. Therefore, the amount of $1.25$ TON, which can be represented in Tact as [`ton("1.25"){:tact}`](/ref/api-comptime#ton), is actually the number $1250000000$. We refer to such numbers as _nano-tons_ (or _nanoToncoins_) rather than _cents_.
Similarly, working with Toncoins requires nine decimal places instead of the two. Therefore, the amount of $1.25$ TON, which can be represented in Tact as [`ton("1.25"){:tact}`](/ref/core-comptime#ton), is actually the number $1250000000$. We refer to such numbers as _nano-tons_ (or _nanoToncoins_) rather than _cents_.

## Serialization

Expand Down
4 changes: 2 additions & 2 deletions pages/book/operators.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This page lists all the operators in Tact in decreasing order of their [preceden

<Callout>

Note, that there are no implicit type conversions in Tact, so operators can't be used to, say, add values of different type or compare them in terms of equality without explicitly casting to the same type. That's done with certain functions from the standard library. See [`Int.toString(){:tact}`](/ref/api-strings#inttostring) for an example of such function.
Note, that there are no implicit type conversions in Tact, so operators can't be used to, say, add values of different type or compare them in terms of equality without explicitly casting to the same type. That's done with certain functions from the standard library. See [`Int.toString(){:tact}`](/ref/core-strings#inttostring) for an example of such function.

</Callout>

Expand Down Expand Up @@ -211,7 +211,7 @@ two % 1; // 1
-1 % -5; // -1
```

The simplest way to avoid confusion between the two is to prefer using positive values via [`abs(x: Int){:tact}`](/ref/api-math#abs):
The simplest way to avoid confusion between the two is to prefer using positive values via [`abs(x: Int){:tact}`](/ref/core-math#abs):

```tact
abs(-1) % abs(-5); // 1
Expand Down
4 changes: 2 additions & 2 deletions pages/book/structs-and-messages.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ fun convertationFun() {
<Callout>

See those extension functions in the Reference:\
[`Struct.toCell(){:tact}`](/book/api-cells#structtocell)\
[`Message.toCell(){:tact}`](/book/api-cells#messagetocell)
[`Struct.toCell(){:tact}`](/ref/api-cells#structtocell)\
[`Message.toCell(){:tact}`](/ref/api-cells#messagetocell)

</Callout>

Expand Down
30 changes: 18 additions & 12 deletions pages/ref/core-advanced.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ Various niche, dangerous or unstable features which can produce unexpected resul

</Callout>

## readForwardFee
## Context.readForwardFee

```tact
extends fun readForwardFee(self: Context): Int
```

Extension function for the [`Context{:tact}`](/ref/api-common#context).
Extension function for the [`Context{:tact}`](/ref/core-common#context).

Reads [forward fee](https://docs.ton.org/develop/smart-contracts/guidelines/processing) and returns it as [`Int{:tact}`][int] value in nanoToncoins (nano-tons).

Expand All @@ -32,20 +32,26 @@ let fwdFee: Int = context().readForwardFee();
fun getConfigParam(id: Int): Cell?;
```

Loads network configuration parameter from the blockchain.
Loads a [configuration parameter](https://docs.ton.org/develop/howto/blockchain-configs) of TON Blockchain by its `id` number.

Usage example:
Usage examples:

```tact
let iDemand: Cell = getConfigParam(0)!!;
// Parameter 0, address of a special smart contract that stores the blockchain's configuration
let configAddrAsCell: Cell = getConfigParam(0)!!;

// Parameter 18, configuration for determining the prices for data storage
let dataStorageFeeConfig: Cell = getConfigParam(18)!!;
```

<Callout>

A standard library [`@stdlib/config`](/ref/stdlib-config) provides two related helper functions:\
Standard library [`@stdlib/config`](/ref/stdlib-config) provides two related helper functions:\
[`getConfigAddress(){:tact}`](/ref/stdlib-config#getconfigaddress) for retrieving config [`Address{:tact}`][p]\
[`getElectorAddress(){:tact}`](/ref/stdlib-config#getconfigaddress) for retrieving elector [`Address{:tact}`][p]

Read more about other parameters: [Config Parameters in TON Docs](https://docs.ton.org/develop/howto/blockchain-configs).

</Callout>

## acceptMessage
Expand Down Expand Up @@ -101,7 +107,7 @@ throw(42); // and this won't fail it
fun nativePrepareRandom();
```

Prepares a random number generator by using [`nativeRandomizeLt(){:tact}`](#nativerandomizelt). Automatically called by [`randomInt(){:tact}`](/ref/api-random#randomint) and [`random(){:tact}`](/ref/api-random#random) functions.
Prepares a random number generator by using [`nativeRandomizeLt(){:tact}`](#nativerandomizelt). Automatically called by [`randomInt(){:tact}`](/ref/core-random#randomint) and [`random(){:tact}`](/ref/core-random#random) functions.

Usage example:

Expand Down Expand Up @@ -148,11 +154,11 @@ let idk: Int = randomInt(); // ???, it's random!
fun nativeRandom(): Int;
```

Generates and returns an $256$-bit random number just like [`randomInt(){:tact}`](/ref/api-random#randomint), but doesn't initialize the random generator with [`nativePrepareRandom(){:tact}`](#nativepreparerandom) beforehand.
Generates and returns an $256$-bit random number just like [`randomInt(){:tact}`](/ref/core-random#randomint), but doesn't initialize the random generator with [`nativePrepareRandom(){:tact}`](#nativepreparerandom) beforehand.

<Callout>

Don't use this function directly, and prefer using [`randomInt(){:tact}`](/ref/api-random#randomint) instead.
Don't use this function directly, and prefer using [`randomInt(){:tact}`](/ref/core-random#randomint) instead.

</Callout>

Expand All @@ -162,11 +168,11 @@ Generates and returns an $256$-bit random number just like [`randomInt(){:tact}`
fun nativeRandomInterval(max: Int): Int;
```

Generates and returns a $256$-bit random number in the range from $0$ to `max` similar to [`random(){:tact}`](/ref/api-random#random), but doesn't initialize the random generator with [`nativePrepareRandom(){:tact}`](#nativepreparerandom) beforehand.
Generates and returns a $256$-bit random number in the range from $0$ to `max` similar to [`random(){:tact}`](/ref/core-random#random), but doesn't initialize the random generator with [`nativePrepareRandom(){:tact}`](#nativepreparerandom) beforehand.

<Callout>

Don't use this function directly, and prefer using [`random(){:tact}`](/ref/api-random#random) instead.
Don't use this function directly, and prefer using [`random(){:tact}`](/ref/core-random#random) instead.

</Callout>

Expand All @@ -180,7 +186,7 @@ Sends the message by specifying the complete `cell` and the [message `mode`](/bo

<Callout>

Prefer using a much more common and user-friendly [`send(){:tact}`](/ref/api-common#send) function unless you have a complex logic that can't be expressed otherwise.
Prefer using a much more common and user-friendly [`send(){:tact}`](/ref/core-common#send) function unless you have a complex logic that can't be expressed otherwise.

</Callout>

Expand Down
2 changes: 1 addition & 1 deletion pages/ref/core-base.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ In case reservation attempt fails and in the default case without the attempt, t
<Callout>

Note, that `self.forward(){:tact}` never sends additional Toncoins on top of what's available on the balance.\
To be able to send more Toncoins with a single message, use the the [`send(){:tact}`](/ref/api-common#send) function.
To be able to send more Toncoins with a single message, use the the [`send(){:tact}`](/ref/core-common#send) function.

</Callout>

Expand Down
4 changes: 2 additions & 2 deletions pages/ref/core-common.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Usage example:

```tact
receive() {
let whoSentMeMessage: Address = sender();
let whoSentMeMessage: Address = sender();
}
```

Expand Down Expand Up @@ -120,7 +120,7 @@ fun newAddress(chain: Int, hash: Int): Address;

Creates a new [`Address{:tact}`][p] based on the [`chain` id](https://ton-blockchain.github.io/docs/#/overviews/TON_blockchain_overview) and the [SHA-256](/ref/stdlib-math#sha256) encoded [`hash` value](https://docs.ton.org/learn/overviews/addresses#account-id).

This function tries to resolve constant values in [compile-time](/ref/api-comptime) whenever possible.
This function tries to resolve constant values in [compile-time](/ref/core-comptime) whenever possible.

Usage example:

Expand Down
10 changes: 5 additions & 5 deletions pages/ref/core-math.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ fun pow(base: Int, exp: Int): Int;

Computes and returns the [exponentiation](https://en.wikipedia.org/wiki/Exponentiation) involving two numbers: the `base` and the exponent (or _power_) `exp`. Exponent `exp` must be non-negative, otherwise an error with [exit code 5](/book/exit-codes#5) will be thrown: `Integer out of expected range`.

Note, that this function works both at run-time and at [compile-time](/ref/api-comptime).
Note, that this function works both at run-time and at [compile-time](/ref/core-comptime).

Usage example:

Expand All @@ -147,7 +147,7 @@ contract Example {

<Callout>

List of functions, that only work at compile-time: [API Comptime](/ref/api-comptime).
List of functions, that only work at compile-time: [API Comptime](/ref/core-comptime).

</Callout>

Expand All @@ -157,7 +157,7 @@ contract Example {
fun pow2(exp: Int): Int;
```

Similar to [`pow(){:tact}`](#pow), but sets the `base` to $2$. Works both at run-time and at [compile-time](/ref/api-comptime).
Similar to [`pow(){:tact}`](#pow), but sets the `base` to $2$. Works both at run-time and at [compile-time](/ref/core-comptime).

Usage examples:

Expand All @@ -184,7 +184,7 @@ contract Example {

<Callout>

List of functions, that only work at compile-time: [API Comptime](/ref/api-comptime).
List of functions, that only work at compile-time: [API Comptime](/ref/core-comptime).

</Callout>

Expand Down Expand Up @@ -260,7 +260,7 @@ Computes and returns the [SHA-256](https://en.wikipedia.org/wiki/SHA-2#Hash_stan

In case `data` is a [`String{:tact}`][p] it should have a number of bits divisible by $8$, and in case it's a [`Slice{:tact}`][p] it must **also** have no references (i.e. only up to 1023 bits of data in total).

This function tries to resolve constant string values in [compile-time](/ref/api-comptime) whenever possible.
This function tries to resolve constant string values in [compile-time](/ref/core-comptime) whenever possible.

Usage examples:

Expand Down
2 changes: 1 addition & 1 deletion pages/ref/core-random.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ let allYourRandomBelongsToUs: Int = randomInt(); // ???, it's random :)

<Callout type="warning" emoji="⚠️">

Advanced functions for working with random numbers are listed on a specialized page: [Advanced APIs](/ref/api-advanced).
Advanced functions for working with random numbers are listed on a specialized page: [Advanced APIs](/ref/core-advanced).

</Callout>

Expand Down
2 changes: 1 addition & 1 deletion pages/ref/core-strings.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ extends fun toSlice(self: StringBuilder): Slice;

Extension function for the [`StringBuilder{:tact}`][p].

Returns an assembled [`Cell{:tact}`][p] as a [`Slice{:tact}`][p] from a [`StringBuilder{:tact}`][p]. Alias to [`self.toCell().asSlice(){:tact}`](/ref/api-cells#cellasslice).
Returns an assembled [`Cell{:tact}`][p] as a [`Slice{:tact}`][p] from a [`StringBuilder{:tact}`][p]. Alias to [`self.toCell().asSlice(){:tact}`](/ref/core-cells#cellasslice).

Usage example:

Expand Down
Loading