# 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:
# Deploy dApp Script
- 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)]) };
- 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
- 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 ) };
- 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
- Prepare your smart asset script:
// Script example: {-# STDLIB_VERSION 6 #-} {-# CONTENT_TYPE EXPRESSION #-} {-# SCRIPT_TYPE ASSET #-} func trueReturner () = { true } trueReturner()
- 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()";