Skip to content
Open
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
8 changes: 4 additions & 4 deletions content/contract-dev/techniques/gas.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ fun onInternalMessage(in: InMessage) {
maxCells,
);
val oldBalance = contract.getOriginalBalance() - in.valueCoins;
reserveToncoinsOnBalance(
reserveGramsOnBalance(
max(oldBalance, minTonsForStorage),
RESERVE_MODE_AT_MOST,
);
Expand Down Expand Up @@ -311,7 +311,7 @@ import "@stdlib/gas-payments";

fun onInternalMessage(in: InMessage) {
// Reserve the original balance plus any storage debt
reserveToncoinsOnBalance(
reserveGramsOnBalance(
contract.getStorageDuePayment(),
RESERVE_MODE_INCREASE_BY_ORIGINAL_BALANCE | RESERVE_MODE_EXACT_AMOUNT,
);
Expand All @@ -334,7 +334,7 @@ If the remaining trace involves `n` unique contracts, no more than `n` freeze li
</Callout>

```tolk title="Tolk"
const FreezeDueLimit: coins = ton("0.1"); // Current mainnet freeze_due_limit.
const FreezeDueLimit: coins = grams("0.1"); // Current mainnet freeze_due_limit.

fun onInternalMessage(in: InMessage) {
// The trace is still receiver -> A -> B
Expand Down Expand Up @@ -369,7 +369,7 @@ The final code in the receiver contract could look like this:
```tolk title="Tolk"
import "@stdlib/gas-payments";

const FreezeDueLimit: coins = ton("0.1"); // Current mainnet freeze_due_limit.
const FreezeDueLimit: coins = grams("0.1"); // Current mainnet freeze_due_limit.

fun onInternalMessage(in: InMessage) {
val workchain = contract.getAddress().getWorkchain();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ fun onInternalMessage(in: InMessage) {
calculateGasFeeWithoutFlatPrice(-1, sizeCountingGas) +
calculateStorageFee(-1, DEFAULT_DURATION, orderBits, orderCells);

reserveToncoinsOnBalance(toReserve, RESERVE_MODE_BOUNCE_ON_ACTION_FAIL);
reserveGramsOnBalance(toReserve, RESERVE_MODE_BOUNCE_ON_ACTION_FAIL);

val reply = createMessage({
bounce: BounceMode.NoBounce,
Expand Down
6 changes: 3 additions & 3 deletions content/standard/tokens/nft/deploy.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ struct NftItemInitAtDeployment {
struct (0x00000001) DeployNft {
queryId: uint64
itemIndex: uint64
attachTonAmount: coins
attachGrams: coins
initParams: Cell<NftItemInitAtDeployment>
}

Expand All @@ -206,7 +206,7 @@ fun onInternalMessage(in: InMessage) {
queryId: 0,
itemIndex: <INDEX>,
// will be sent to the item contract on deployment
attachTonAmount: ton("0.005"),
attachGrams: grams("0.005"),
initParams: NftItemInitAtDeployment {
recipientAddress: address("<RECIPIENT_ADDRESS>"),
content: ("<ITEM_CONTENT>" as SnakeString).toCell()
Expand All @@ -216,7 +216,7 @@ fun onInternalMessage(in: InMessage) {
val msg = createMessage({
bounce: true,
dest: address("<COLLECTION_ADDRESS>"),
value: ton("0.01"),
value: grams("0.01"),
body: deploy
});

Expand Down
4 changes: 2 additions & 2 deletions content/tolk/basic-syntax.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ Constants can be declared only at the top level, not inside functions:

```tolk
const ONE = 1
const MAX_AMOUNT = ton("0.05")
const MAX_AMOUNT = grams("0.05")
const ADMIN_ADDRESS = address("EQ...")
```

Expand Down Expand Up @@ -292,7 +292,7 @@ To [construct and send a message](/languages/tolk/features/message-sending), a m
```tolk
val reply = createMessage({
bounce: BounceMode.NoBounce,
value: ton("0.05"),
value: grams("0.05"),
dest: someAddress,
body: RequestedInfo { ... }
});
Expand Down
58 changes: 29 additions & 29 deletions content/tolk/examples.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ Some files in the source directory are not runnable on their own and depend on o
>
```tolk
// 6905(computational_gas_price) * 1000(cur_gas_price) = 6905000 ~= 0.01 TON
const MINIMAL_MESSAGE_VALUE_BOUND = ton("0.01")
const MIN_TONS_FOR_STORAGE = ton("0.01")
const JETTON_WALLET_GAS_CONSUMPTION = ton("0.015")
const MINIMAL_MESSAGE_VALUE_BOUND = grams("0.01")
const MIN_GRAMS_FOR_STORAGE = grams("0.01")
const JETTON_WALLET_GAS_CONSUMPTION = grams("0.015")
```
</Accordion>

Expand Down Expand Up @@ -102,7 +102,7 @@ Some files in the source directory are not runnable on their own and depend on o
transferRecipient: address
sendExcessesTo: address?
customPayload: cell?
forwardTonAmount: coins
forwardGrams: coins
forwardPayload: ForwardPayloadRemainder
}

Expand All @@ -119,7 +119,7 @@ Some files in the source directory are not runnable on their own and depend on o
// is null when minting (not initiated by another wallet)
transferInitiator: address?
sendExcessesTo: address?
forwardTonAmount: coins
forwardGrams: coins
forwardPayload: ForwardPayloadRemainder
}

Expand Down Expand Up @@ -156,7 +156,7 @@ Some files in the source directory are not runnable on their own and depend on o
struct (0x00000015) MintNewJettons {
queryId: uint64
mintRecipient: address
tonAmount: coins
gramAmount: coins
internalTransferMsg: Cell<InternalTransferStep>
}

Expand Down Expand Up @@ -312,7 +312,7 @@ Some files in the source directory are not runnable on their own and depend on o
contract.getAddress(),
storage.jettonWalletCode,
),
value: msg.tonAmount,
value: msg.gramAmount,
// a newly-deployed wallet contract will immediately handle it
body: msg.internalTransferMsg,
});
Expand Down Expand Up @@ -426,20 +426,20 @@ Some files in the source directory are not runnable on their own and depend on o

var msgValue = in.valueCoins;
var tonBalanceBeforeMsg = contract.getOriginalBalance() - msgValue;
var storageFee = MIN_TONS_FOR_STORAGE - min(
var storageFee = MIN_GRAMS_FOR_STORAGE - min(
tonBalanceBeforeMsg,
MIN_TONS_FOR_STORAGE,
MIN_GRAMS_FOR_STORAGE,
);
msgValue -= (storageFee + JETTON_WALLET_GAS_CONSUMPTION);

if (msg.forwardTonAmount) {
msgValue -= (msg.forwardTonAmount + in.originalForwardFee);
if (msg.forwardGrams) {
msgValue -= (msg.forwardGrams + in.originalForwardFee);

val notifyOwnerMsg = createMessage({
// cause receiver can have uninitialized contract
bounce: BounceMode.NoBounce,
dest: storage.ownerAddress,
value: msg.forwardTonAmount,
value: msg.forwardGrams,
body: TransferNotificationForRecipient {
queryId: msg.queryId,
jettonAmount: msg.jettonAmount,
Expand Down Expand Up @@ -477,13 +477,13 @@ Some files in the source directory are not runnable on their own and depend on o
storage.jettonBalance -= msg.jettonAmount;
storage.save();

var forwardedMessagesCount = msg.forwardTonAmount ? 2 : 1;
var forwardedMessagesCount = msg.forwardGrams ? 2 : 1;
assert (in.valueCoins >
msg.forwardTonAmount +
msg.forwardGrams +
// 3 messages: wal1->wal2, wal2->owner, wal2->response
// but last one is optional (it is ok if it fails)
forwardedMessagesCount * in.originalForwardFee +
(2 * JETTON_WALLET_GAS_CONSUMPTION + MIN_TONS_FOR_STORAGE)
(2 * JETTON_WALLET_GAS_CONSUMPTION + MIN_GRAMS_FOR_STORAGE)
) throw ERR_NOT_ENOUGH_TON;

val deployMsg = createMessage({
Expand All @@ -499,7 +499,7 @@ Some files in the source directory are not runnable on their own and depend on o
jettonAmount: msg.jettonAmount,
transferInitiator: storage.ownerAddress,
sendExcessesTo: msg.sendExcessesTo,
forwardTonAmount: msg.forwardTonAmount,
forwardGrams: msg.forwardGrams,
forwardPayload: msg.forwardPayload,
}
});
Expand Down Expand Up @@ -594,7 +594,7 @@ Some files in the source directory are not runnable on their own and depend on o
title="fees-management.tolk"
>
```tolk
const MIN_TONS_FOR_STORAGE = ton("0.05")
const MIN_GRAMS_FOR_STORAGE = grams("0.05")
```
</Accordion>

Expand Down Expand Up @@ -738,7 +738,7 @@ Some files in the source directory are not runnable on their own and depend on o
struct (0x00000001) DeployNft {
queryId: uint64
itemIndex: uint64
attachTonAmount: coins
attachGrams: coins
initParams: Cell<NftItemInitAtDeployment>
}

Expand All @@ -748,7 +748,7 @@ Some files in the source directory are not runnable on their own and depend on o
}

struct BatchDeployDictItem {
attachTonAmount: coins
attachGrams: coins
initParams: Cell<NftItemInitAtDeployment>
}

Expand Down Expand Up @@ -782,7 +782,7 @@ Some files in the source directory are not runnable on their own and depend on o
newOwnerAddress: address
sendExcessesTo: address?
customPayload: dict
forwardTonAmount: coins
forwardGrams: coins
forwardPayload: RemainingBitsAndRefs
}
```
Expand All @@ -799,7 +799,7 @@ Some files in the source directory are not runnable on their own and depend on o
fun deployNftItem(
itemIndex: int,
nftItemCode: cell,
attachTonAmount: coins,
attachGrams: coins,
initParams: Cell<NftItemInitAtDeployment>,
) {
val deployMsg = createMessage({
Expand All @@ -809,7 +809,7 @@ Some files in the source directory are not runnable on their own and depend on o
contract.getAddress(),
nftItemCode,
),
value: attachTonAmount,
value: attachGrams,
body: initParams,
});
deployMsg.send(SEND_MODE_PAY_FEES_SEPARATELY);
Expand All @@ -836,7 +836,7 @@ Some files in the source directory are not runnable on their own and depend on o
deployNftItem(
msg.itemIndex,
storage.nftItemCode,
msg.attachTonAmount,
msg.attachGrams,
msg.initParams,
);
if (isLast) {
Expand Down Expand Up @@ -879,7 +879,7 @@ Some files in the source directory are not runnable on their own and depend on o
deployNftItem(
itemIndex,
storage.nftItemCode,
dictItem.attachTonAmount,
dictItem.attachGrams,
dictItem.initParams,
);
if (itemIndex == storage.nextItemIndex) {
Expand Down Expand Up @@ -1013,9 +1013,9 @@ Some files in the source directory are not runnable on their own and depend on o
throw ERROR_INVALID_WORKCHAIN;

val fwdFee = in.originalForwardFee;
var restAmount = contract.getOriginalBalance() - MIN_TONS_FOR_STORAGE;
if (msg.forwardTonAmount) {
restAmount -= (msg.forwardTonAmount + fwdFee);
var restAmount = contract.getOriginalBalance() - MIN_GRAMS_FOR_STORAGE;
if (msg.forwardGrams) {
restAmount -= (msg.forwardGrams + fwdFee);
}
if (msg.sendExcessesTo != null) {
assert (msg.sendExcessesTo.getWorkchain() == BASECHAIN)
Expand All @@ -1026,11 +1026,11 @@ Some files in the source directory are not runnable on their own and depend on o
// base nft spends fixed amount of gas, will not check for response
assert (restAmount >= 0) throw ERROR_TOO_SMALL_REST_AMOUNT;

if (msg.forwardTonAmount) {
if (msg.forwardGrams) {
val ownershipMsg = createMessage({
bounce: BounceMode.NoBounce,
dest: msg.newOwnerAddress,
value: msg.forwardTonAmount,
value: msg.forwardGrams,
body: NotificationForNewOwner {
queryId: msg.queryId,
oldOwnerAddress: storage.ownerAddress,
Expand Down
12 changes: 6 additions & 6 deletions content/tolk/features/message-sending.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Tolk provides a high-level function `createMessage`, which is followed by `send`
```tolk
val reply = createMessage({
bounce: BounceMode.NoBounce,
value: ton("0.05"),
value: grams("0.05"),
dest: senderAddress,
body: RequestedInfo { ... }
});
Expand All @@ -20,16 +20,16 @@ When handling a message, some values can be represented in multiple valid forms.

### Message value

The message value consists of a Toncoin amount:
The message value consists of a GRAM amount:

```tolk
value: someTonAmount
value: someGramAmount
```

When extra currencies are required, the message value includes both Toncoin and a dictionary:
When extra currencies are required, the message value includes both GRAM and a dictionary:

```tolk
value: (someTonAmount, extraDict)
value: (someGramAmount, extraDict)
```

This is possible because the `value` field is defined as a union:
Expand Down Expand Up @@ -250,7 +250,7 @@ While a field `stateInit: ContractState | cell` is named as `stateInit`, emphasi

## `createExternalLogMessage`

`createExternalLogMessage` follows the same general model as `createMessage`. [External outgoing messages](/foundations/messages/external-out) do not support bounce behavior, attached Toncoin, or related options, so the set of available fields is different. External messages are used only for emitting logs intended for indexers.
`createExternalLogMessage` follows the same general model as `createMessage`. [External outgoing messages](/foundations/messages/external-out) do not support bounce behavior, attached GRAM, or related options, so the set of available fields is different. External messages are used only for emitting logs intended for indexers.

Example:

Expand Down
24 changes: 14 additions & 10 deletions content/tolk/features/standard-library.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,21 @@ const hexSlice = "1020".hexToSlice()
const rawSlice = "abcd".literalSlice()
```

### `ton()`
### `grams()`

Calculates nanotoncoins at compile time.
Calculates nanograms at compile time.

```tolk
const ONE_TON = ton("1"); // `coins`, value: 1000000000
const ONE_GRAM = grams("1"); // `coins`, value: 1000000000

fun calcCost() {
val cost = ton("0.05"); // `coins`, value: 50000000
return ONE_TON + cost;
val cost = grams("0.05"); // `coins`, value: 50000000
return ONE_GRAM + cost;
}
```

The old `ton()` function is still available for backward compatibility, but `grams()` is preferred.

## Common functions

All functions in this section are available everywhere. They are defined in `@stdlib/common.tolk`, which is auto-imported.
Expand Down Expand Up @@ -171,7 +173,7 @@ Returns `address` — the internal address of the current smart contract. It can

#### `contract.getOriginalBalance`

Returns `coins` — the balance of the smart contract in nanotoncoins at the start of the [compute phase](/tvm/exit-codes#compute-phase).
Returns `coins` — the balance of the smart contract in nanograms at the start of the [compute phase](/tvm/exit-codes#compute-phase).

#### `contract.getOriginalBalanceWithExtraCurrencies`

Expand Down Expand Up @@ -394,17 +396,19 @@ Checks which specific blockchain address is contained in `any_address`.
Casts `any_address` to `address`, with a runtime check that the value is internal. To skip the check, use an [unsafe cast](/languages/tolk/types/type-checks-and-casts):
`addr = myAny as address`.

### Reserving Toncoin on the contract balance
### Reserving GRAM on the contract balance

The standard library provides several `RESERVE_MODE_XXX` constants for [reserve modes](/foundations/actions/reserve), as well as the following functions.

#### `reserveToncoinsOnBalance`
#### `reserveGramsOnBalance`

Creates an output action that reserves GRAM on the contract balance.

Creates an output action that reserves Toncoin on the contract balance.
`reserveToncoinsOnBalance` is a deprecated alias for `reserveGramsOnBalance`.

#### `reserveExtraCurrenciesOnBalance`

Similar to `reserveToncoinsOnBalance`, but also accepts a dictionary `extraAmount`.
Similar to `reserveGramsOnBalance`, but also accepts a dictionary `extraAmount`.

### Creating and sending messages

Expand Down
2 changes: 1 addition & 1 deletion content/tolk/from-func/stdlib-comparison.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ Other functions:
| `parse_std_addr` | use `address` type |
| `parse_var_addr` | _(deleted)_ |
| `config_param` | `blockchain.configParam` |
| `raw_reserve` | `reserveToncoinsOnBalance` |
| `raw_reserve` | `reserveGramsOnBalance` |
| `raw_reserve_extra` | `reserveExtraCurrenciesOnBalance` |
| `send_raw_message` | use `createMessage` |
| `set_code` | `contract.setCodePostponed` |
Expand Down
Loading
Loading