waves_logo Docs
  • Overview
    Overview
  • How-to Guides
    • Reading Blockchain Data
      Reading Blockchain Data
    • Creating & Broadcasting Transactions
      Creating & Broadcasting Transactions
    • Tokenization
      Tokenization
    • Airdrop
      Airdrop
    • Payments
      Payments
    • Exchange Tokens
      Exchange Tokens
    • Simple Voting
      Simple Voting
    • List as argument
      List as argument
    How-to Guides
  • Waves Smart Contracts
    Waves Smart Contracts
  • dApp
    • Creating & Launching dApp
      Creating & Launching dApp
    dApp
  • Smart Account
    • Creating smart account
      Creating smart account
    • Creating and deploying a script manually
      Creating and deploying a script manually
    • Video tutorials
      • Introduction to the Waves blockchain, Waves Smart Accounts and Waves Smart Assets
        Introduction to the Waves blockchain, Waves Smart Accounts and Waves Smart Assets
      • Waves Smart Account with multisignature
        Waves Smart Account with multisignature
      • Waves Smart Account with escrow service
        Waves Smart Account with escrow service
      • Creating multisignature account via Waves IDE tools
        Creating multisignature account via Waves IDE tools
      • Creating multisignature account via Waves Client
        Creating multisignature account via Waves Client
      • Waves console explained
        Waves console explained
      Video tutorials
    Smart Account
  • Smart Asset
    Smart Asset
  • Developer Tools
    • Waves IDE
      Waves IDE
    • Visual Studio Code Extension
      Visual Studio Code Extension
    • Surfboard
      Surfboard
    • Ride REPL
      Ride REPL
    Developer Tools
  • Signer ◆
    Signer ◆
  • Waves API
    • Data Service API
      Data Service API
    • Node REST API
      Node REST API
    • Node gRPC Server
      Node gRPC Server
    • Blockchain Updates
      Blockchain Updates
    Waves API
  • Client Libraries
    • Waves C#
      • Install SDK
        Install SDK
      • Run Code Sample
        • Send Transactions
          Send Transactions
        • Use Crypto Utilities
          Use Crypto Utilities
        • Interact With Node
          Interact With Node
        • Set Up Smart Contracts
          Set Up Smart Contracts
        Run Code Sample
      Waves C#
    • Gowaves
      • Install SDK
        Install SDK
      Gowaves
    • WavesJ
      • Install SDK
        Install SDK
      WavesJ
    • Ts-lib-crypto
      • Install SDK
        Install SDK
      Ts-lib-crypto
    • Waves-PHP
      • Install SDK
        Install SDK
      Waves-PHP
    • Waves-python
      • Install SDK
        Install SDK
      Waves-python
    • Waves-rust
      • Install SDK
        Install SDK
      Waves-rust
    Client Libraries
      • English
      • Русский
      On this page
        • Prerequisites
        • Tutorial
      waves_logo Docs

          # Set Up Smart Contracts

          Deploy a smart contract after meeting the prerequisites.

          # Prerequisites

          • Wallet: Set up a wallet via Keeper Wallet or WX Network .

            NOTE: Ensure saving your wallet's seed phrase to send transactions.

          • Tokens: Obtain WAVES tokens to cover the transaction fee for each script deployment:
            • For the Mainnet network: Get 0.001 WAVES via Available Market Options .
            • For the Testnet network: Get 0.001 WAVES via Faucet .
            • For the Stagenet network: Get 0.001 WAVES via Faucet .

          # Tutorial

          Follow the steps for the relevant smart contract type:

          • dApp.
          • Smart Account.
          • Smart Asset.

          # Deploy dApp Script

          1. Prepare your dApp script:
            // Script example:
            {-# STDLIB_VERSION 3 #-}
            {-# SCRIPT_TYPE ACCOUNT #-}
            {-# CONTENT_TYPE DAPP #-}
            let answersCount = 20
            
            let answers =
                ['It is certain.',
                'Yes - definitely.',
                'You may rely on it.',
                'As I see it, yes.',
                'My reply is no.', 
                'My sources say no.',
                'Very doubtful.']
            
            func getAnswer (question,previousAnswer) = {
                let hash = sha256(toBytes((question + previousAnswer)))
                let index = toInt(hash)
                answers[(index % answersCount)]
            }
            
            func getPreviousAnswer (address) = match getString(this, (address + '_a')) {
                case a: String => a
                case _ => address
            }
            
            @Callable(i)
            func tellme (question) = {
                let callerAddress = toBase58String(i.caller.bytes)
                let answer = getAnswer(question, getPreviousAnswer(callerAddress))
                WriteSet([DataEntry((callerAddress + '_q'), question), DataEntry((callerAddress + '_a'), answer)])
            };
            
          2. Send a Set Script Transaction with:
          • Your seed phrase pasted into the senderPrivateKey variable.

          • Your dApp script pasted into the txScript variable.

            NOTE: Use \n" + to properly format multi-line scripts as a string.

            // Formatting example:
            var txScript = "{-# STDLIB_VERSION 3 #-}\n" +
                "{-# SCRIPT_TYPE ACCOUNT #-}\n" +
                "{-# CONTENT_TYPE DAPP #-}\n" +
                "let answersCount = 20\n" +
            
                "let answers =\n" +
                "['It is certain.',\n" +
                "'Yes - definitely.',\n" +
                "'You may rely on it.',\n" +
                "'As I see it, yes.',\n" +
                "'My reply is no.', \n" +
                "'My sources say no.',\n" +
                "'Very doubtful.']\n" +
            
                "func getAnswer (question,previousAnswer) = {\n" +
                    "let hash = sha256(toBytes((question + previousAnswer)))\n" +
                    "let index = toInt(hash)\n" +
                    "answers[(index % answersCount)]\n" +
                "}\n" +
            
                "func getPreviousAnswer (address) = match getString(this, (address + '_a')) {\n" +
                    "case a: String => a\n" +
                    "case _ => address\n" +
                "}\n" +
            
                "@Callable(i)\n" +
                "func tellme (question) = {\n" +
                    "let callerAddress = toBase58String(i.caller.bytes)\n" +
                    "let answer = getAnswer(question, getPreviousAnswer(callerAddress))\n" +
                    "WriteSet([DataEntry((callerAddress + '_q'), question), DataEntry((callerAddress + '_a'), answer)])\n" +
                "}";
            

          # Deploy Smart Account Script

          1. Prepare your smart asset script:
            // Script example:
            {-# STDLIB_VERSION 6 #-}
            {-# CONTENT_TYPE EXPRESSION #-}
            {-# SCRIPT_TYPE ACCOUNT #-}
            
            let cooperPubKey = base58'BVqYXrapgJP9atQccdBPAgJPwHDKkh6A8'
            let BTCId = base58'8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS'
            match tx {
                case o: Order =>
                    sigVerify(o.bodyBytes, o.proofs[0], cooperPubKey ) && 
                    (o.assetPair.priceAsset == BTCId || o.assetPair.amountAsset == BTCId)
                case _ => sigVerify(tx.bodyBytes, tx.proofs[0], cooperPubKey )
            };
            
          2. Send a Set Script Transaction with:
          • Your seed phrase pasted into the senderPrivateKey variable.

          • Your smart asset script pasted into the txScript variable.

            NOTE: Use \n" + to properly format multi-line scripts as a string:

            // Formatting example:
            var txScript = "{-# STDLIB_VERSION 6 #-}\n" +
                "{-# CONTENT_TYPE EXPRESSION #-}\n" +
                "{-# SCRIPT_TYPE ACCOUNT #-}\n" +
                "let cooperPubKey = base58'BVqYXrapgJP9atQccdBPAgJPwHDKkh6A8'\n" +
                "let BTCId = base58'8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS'\n" +
                "match tx {\n" +
                    "case o: Order =>\n" +
                        "sigVerify(o.bodyBytes, o.proofs[0], cooperPubKey ) && \n" +
                        "(o.assetPair.priceAsset == BTCId || o.assetPair.amountAsset == BTCId)\n" +
                    "case _ => sigVerify(tx.bodyBytes, tx.proofs[0], cooperPubKey )\n" +
                "}";
            

          # Deploy Smart Asset Script

          1. Prepare your smart asset script:
            // Script example:
            {-# STDLIB_VERSION 6 #-}
            {-# CONTENT_TYPE EXPRESSION #-}
            {-# SCRIPT_TYPE ASSET #-}
            
            func trueReturner () = {
                true
            }
            trueReturner()
            
          2. Follow the steps based on your goal:
          • To create a new smart asset with the defined script.
          • To add a smart asset script to an existing asset.

          # Create Smart Asset

          Send an Issue Transaction with:

          • Your seed phrase pasted into the senderPrivateKey variable.

          • Your smart asset script pasted into the txScript variable.

            NOTE: Use \n" + to properly format multi-line scripts as a string:

            // Formatting example:
            var txScript =
                "{-# STDLIB_VERSION 6 #-}\n" +
                "{-# CONTENT_TYPE EXPRESSION #-}\n" +
                "{-# SCRIPT_TYPE ASSET #-}\n" +
                "func trueReturner() = {\n" +
                    "true\n" +
                "}\n" +
                "trueReturner()";
            

          # Add Asset Script

          Send a Set Asset Script Transaction with:

          • Your seed phrase pasted into the senderPrivateKey variable.

          • Your asset ID pasted into the assetId variable.

          • Your smart asset script pasted into the script variable.

            NOTE: Use \n" + to properly format multi-line scripts as a string:

            // Formatting example:
            var script =
                "{-# STDLIB_VERSION 6 #-}\n" +
                "{-# CONTENT_TYPE EXPRESSION #-}\n" +
                "{-# SCRIPT_TYPE ASSET #-}\n" +
                "func trueReturner() = {\n" +
                    "true\n" +
                "}\n" +
                "trueReturner()";
            
          Interact With Node
          Gowaves
          Interact With Node
          Gowaves