Venom Docs
  • General
    • Welcome to Venom
    • What's New
    • Ecosystem
    • Create a new Wallet Account
    • Balance Transfers
    • Community
    • Presskit
  • Learn
    • Glossary
    • Architecture
    • Tokens and Assets
    • Messages and Transactions
    • Accounts
  • Build
    • Development Guides
      • Comparing of Ethereum vs Venom architectures
      • Setting Up The Venom Smart Contract Development Environment
      • How to create your own fungible TIP-3 token
        • Fungible tokens in Venom network
        • Quick start developing with TIP-3
        • Venom In Action. Simple Tokensale.
        • Venom In Action. Extend our Tokensale with frontend
        • Venom In Action. Going Global
        • Venom In Action. Ways of code enhancing
      • Developing of simple voting system.
        • Voting system basics
        • Venom In Action. Voting system contracts.
        • Venom In Action. Ways of code enhancing
      • How to create your own non-fungible TIP-4 token
        • Non-Fungible tokens in Venom network
        • Quick start developing with TIP-4
        • Venom In Action. Simple NFT auction
        • Venom In Action. Extend our auction with frontend
    • Integration Guides
      • How to connect Dapp UI to Venom
    • Tools & Resources
  • Maintain
    • Network Maintainers
Powered by GitBook
On this page
  1. Build
  2. Development Guides
  3. How to create your own fungible TIP-3 token

Venom In Action. Ways of code enhancing

Let's go over some best practice point, that will helps us to enhance a code we have. As you remember we have some tvm.rawReserve calls, like

tvm.rawReserve(1 ever, 0);

Moving that gas constants to standalone library is a good form. Same for external calling:

ITokenRoot(distributedTokenRoot).deployWallet {
    value: 0.2 ever,
    flag: 1,
    callback: Tokensale.onTokenWallet
}
(
    address(this),
    0.1 ever
);

Just create some library:

TokensaleGas.sol
pragma ever-solidity >= 0.61.2;

library TokensaleGas {
    uint128 constant INITIAL_BALANCE                                  = 0.7  ever;
    uint128 constant DEPLOY_EMPTY_WALLET_VALUE                        = 0.2  ever;
}

So that allow you to easily change gas variables for you contract

Tokensale.sol
pragma ever-solidity >= 0.61.2;
...
import "./gas/TokensaleGas.sol"

contract Tokensale {
...
        constructor(
                address distributedTokenRoot,
                uint256 supply,
                uint128 rate,
                address sendRemainingGasTo
            ) public {
                tvm.accept();
                tvm.rawReserve(TokesaleGas.INITIAL_BALANCE, 0);
...
                ITokenRoot(distributedTokenRoot).deployWallet {
                    value: TokesaleGas.DEPLOY_EMPTY_WALLET_VALUE,
                    flag: 1,
                    callback: Tokensale.onTokenWallet
                } (
                    address(this),
                    0.1 ever // create a constant for this variable too :)
                );

You can accept same idea for an error codes:

TokensaleErrors.sol
pragma ever-solidity >= 0.61.2;

library TokensaleErrors {
    uint8 constant BAD_ROOT_CALL               = 101;
}
Tokensale.sol
pragma ever-solidity >= 0.61.2;
...

import "./errors/TokensaleErrors.sol"

...

    function onTokenWallet(address value) external {
        require (
            msg.sender.value != 0 &&
            msg.sender == _distributedTokenRoot,
            TokensaleErrors.BAD_ROOT_CALL
        );

...
PreviousVenom In Action. Going GlobalNextDeveloping of simple voting system.

Last updated 2 years ago