 {"id":944,"date":"2023-01-04T05:03:20","date_gmt":"2023-01-03T19:03:20","guid":{"rendered":"https:\/\/test.secrypt.tech\/?page_id=944"},"modified":"2023-01-05T17:56:39","modified_gmt":"2023-01-05T07:56:39","slug":"using-truffle","status":"publish","type":"page","link":"https:\/\/test.secrypt.tech\/index.php\/using-truffle\/","title":{"rendered":"Using Truffle"},"content":{"rendered":"<style>\/*! elementor - v3.9.2 - 21-12-2022 *\/\n.elementor-widget-image{text-align:center}.elementor-widget-image a{display:inline-block}.elementor-widget-image a img[src$=\".svg\"]{width:48px}.elementor-widget-image img{vertical-align:middle;display:inline-block}<\/style>\n<p>\t\t\t\t\t\t\t\t\t\t\t\t\t<a href=\"https:\/\/test.secrypt.tech\/\"><br \/>\n\t\t\t\t\t\t\t<img decoding=\"async\" src=\"https:\/\/test.secrypt.tech\/wp-content\/uploads\/elementor\/thumbs\/image-removebg-preview-pusb43b4fkgjv12hawycptkh3fmhfjngdaesxsjilk.png\" title=\"image-removebg-preview\" alt=\"image-removebg-preview\" \/>\t\t\t\t\t\t\t\t<\/a><\/p>\n<style>\/*! elementor - v3.9.2 - 21-12-2022 *\/\n.elementor-column .elementor-spacer-inner{height:var(--spacer-size)}.e-con{--container-widget-width:100%}.e-con-inner>.elementor-widget-spacer,.e-con>.elementor-widget-spacer{width:var(--container-widget-width,var(--spacer-size));--align-self:var(--container-widget-align-self,initial);--flex-shrink:0}.e-con-inner>.elementor-widget-spacer>.elementor-widget-container,.e-con-inner>.elementor-widget-spacer>.elementor-widget-container>.elementor-spacer,.e-con>.elementor-widget-spacer>.elementor-widget-container,.e-con>.elementor-widget-spacer>.elementor-widget-container>.elementor-spacer{height:100%}.e-con-inner>.elementor-widget-spacer>.elementor-widget-container>.elementor-spacer>.elementor-spacer-inner,.e-con>.elementor-widget-spacer>.elementor-widget-container>.elementor-spacer>.elementor-spacer-inner{height:var(--container-widget-height,var(--spacer-size))}<\/style>\n<style>\/*! elementor - v3.9.2 - 21-12-2022 *\/\n.elementor-heading-title{padding:0;margin:0;line-height:1}.elementor-widget-heading .elementor-heading-title[class*=elementor-size-]>a{color:inherit;font-size:inherit;line-height:inherit}.elementor-widget-heading .elementor-heading-title.elementor-size-small{font-size:15px}.elementor-widget-heading .elementor-heading-title.elementor-size-medium{font-size:19px}.elementor-widget-heading .elementor-heading-title.elementor-size-large{font-size:29px}.elementor-widget-heading .elementor-heading-title.elementor-size-xl{font-size:39px}.elementor-widget-heading .elementor-heading-title.elementor-size-xxl{font-size:59px}<\/style>\n<h2>Deploy a Smart Contract Using Truffle<\/h2>\n<h4><strong>Overview<\/strong><\/h4>\n<p>Truffle\u00a0is a blockchain development environment, which you can use to create and test smart contracts by leveraging the Ethereum Virtual Machine. This guide aims at teaching how to create a smart contract using Truffle and deploying it on the EVM-compatible SECRYPT Network.<\/p>\n<p><b>NOTE<\/b><\/p>\n<p>This tutorial is an adapted version of the\u00a0<u>Truffle quickstart guide<\/u>\u00a0article.<\/p>\n<h4><strong>What you will do<\/strong><\/h4>\n<ul>\n<li>Install and set up Truffle<\/li>\n<li>Deploy contract on SECRYPT Network<\/li>\n<li>Check the deployment status on SECRYPT scan<\/li>\n<\/ul>\n<h5><strong>Prerequisites<\/strong><\/h5>\n<p>There are a few technical requirements before we start. Please install the following:<\/p>\n<ul>\n<li>Node.js v8+ LTS and npm\u00a0(packaged with Node)<\/li>\n<li>Git<\/li>\n<\/ul>\n<p>Once we have those installed, we only need one command to install Truffle:<\/p>\n<p>npm install -g truffle<\/p>\n<p>To verify that Truffle is installed properly, type\u00a0truffle version\u00a0on a terminal. If you see an error, make sure that the npm modules are added to your path.<\/p>\n<h4><strong>Creating a Project<\/strong><\/h4>\n<h5><strong>MetaCoin Project<\/strong><\/h5>\n<p>We will use one of Truffle&#8217;s boilerplates which you can find on their\u00a0Truffle Boxes\u00a0page.\u00a0MetaCoin box\u00a0creates a token that can be transferred between accounts.<\/p>\n<ol>\n<li>Start by creating a new directory for this Truffle project:<\/li>\n<\/ol>\n<p>mkdir MetaCoin<br \/>cd MetaCoin<\/p>\n<ol>\n<li>Download the MetaCoin box:<\/li>\n<\/ol>\n<p>truffle unbox metacoin<\/p>\n<p>With that last step, you have created a Truffle project cointaining folders with contracts, deployment, testing, and configuration files.<\/p>\n<p>This is the smart contract data from the\u00a0metacoin.sol\u00a0file:<\/p>\n<p>metacoin.sol<\/p>\n<p><em>\/\/ SPDX-License-Identifier: MIT<\/em><br \/><em>\/\/ Tells the Solidity compiler to compile only from v0.8.13 to v0.9.0<\/em><br \/>pragma solidity ^0.8.13;<\/p>\n<p>import &#8220;.\/ConvertLib.sol&#8221;;<\/p>\n<p><em>\/\/ This is just a simple example of a coin-like contract.<\/em><br \/><em>\/\/ It is not ERC20 compatible and cannot be expected to talk to other<\/em><br \/><em>\/\/ coin\/token contracts.<\/em><\/p>\n<p>contract MetaCoin {<br \/>\u00a0\u00a0\u00a0 mapping (address =&gt; uint) balances;<\/p>\n<p>\u00a0\u00a0\u00a0 event Transfer(address indexed _from, address indexed _to, uint256 _value);<\/p>\n<p>\u00a0\u00a0\u00a0 constructor() {<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 balances[tx.origin] = 10000;<br \/>\u00a0\u00a0\u00a0 }<\/p>\n<p>\u00a0\u00a0\u00a0 function sendCoin(address receiver, uint amount) public returns(bool sufficient) {<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 if (balances[msg.sender] &lt; amount) return false;<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 balances[msg.sender] -= amount;<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 balances[receiver] += amount;<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 emit Transfer(msg.sender, receiver, amount);<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 return true;<br \/>\u00a0\u00a0\u00a0 }<\/p>\n<p>\u00a0\u00a0\u00a0 function getBalanceInEth(address addr) public view returns(uint){<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 return ConvertLib.convert(getBalance(addr),2);<br \/>\u00a0\u00a0\u00a0 }<\/p>\n<p>\u00a0\u00a0\u00a0 function getBalance(address addr) public view returns(uint) {<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 return balances[addr];<br \/>\u00a0\u00a0\u00a0 }<br \/>}<\/p>\n<p><b>NOTE<\/b><\/p>\n<p>Notice that ConvertLib is being imported just after the\u00a0pragma\u00a0statement. In this project, there are actually two smart contracts that will be deployed at the end: one is Metacoin, contatining all the send and balance logic; the other is ConvertLib, a library used to convert values.<\/p>\n<h4><strong>Testing the Contract<\/strong><\/h4>\n<p>You can run Solidity and Javascript tests.<\/p>\n<ol>\n<li>In a terminal, run the Solidity test:<\/li>\n<\/ol>\n<p>truffle test .\/test\/TestMetaCoin.sol<\/p>\n<p>You should see the following output:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/test.secrypt.tech\/wp-content\/uploads\/2023\/01\/1.png\" alt=\"\" width=\"666\" height=\"187\" \/><\/p>\n<p>2:Run the JavaScript test:<\/p>\n<p>truffle test .\/test\/metacoin.js<\/p>\n<p>You should see the following output:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/test.secrypt.tech\/wp-content\/uploads\/2023\/01\/2.png\" alt=\"\" width=\"766\" height=\"198\" \/><\/p>\n<p><strong>Compiling the Contract<\/strong><strong>\u200b<\/strong><\/p>\n<p>Compile the smart contract using the following command:<\/p>\n<p>truffle compile<\/p>\n<p>You will see the following output:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/test.secrypt.tech\/wp-content\/uploads\/2023\/01\/3.png\" alt=\"\" width=\"969\" height=\"178\" \/><\/p>\n<p><strong>Configuring the Smart Contract<\/strong><strong>\u200b<\/strong><\/p>\n<p>Before actually depolying the contract, you need to set up the\u00a0truffle-config.js\u00a0file, inserting network and compilers data.<\/p>\n<p>Go to\u00a0truffle-config.js\u00a0and update the file with SECRYPT Testnet network details.<\/p>\n<p style=\"text-align: center;\">mkdir ~\/.testsxc<\/p>\n<p>truffle-config.js<\/p>\n<p>const HDWalletProvider = require(&#8216;@truffle\/hdwallet-provider&#8217;);<br \/>const fs = require(&#8216;fs&#8217;);<br \/>const mnemonic = fs.readFileSync(&#8220;.secret&#8221;).toString().trim();<\/p>\n<p>module.exports = {<br \/>\u00a0 networks: {<br \/>\u00a0\u00a0\u00a0 development: {<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0 host: &#8220;127.0.0.1&#8221;,\u00a0\u00a0\u00a0\u00a0 <em>\/\/ Localhost (default: none)<\/em><br \/>\u00a0\u00a0\u00a0\u00a0\u00a0 port: 8545,\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <em>\/\/ Standard Ethereum port (default: none)<\/em><br \/>\u00a0\u00a0\u00a0\u00a0\u00a0 network_id: &#8220;*&#8221;,\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <em>\/\/ Any network (default: none)<\/em><br \/>\u00a0\u00a0\u00a0 },<br \/>\u00a0\u00a0\u00a0 sxc: {<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0 provider: () =&gt; new HDWalletProvider(mnemonic, `http:\/\/ttv-wkqbnkghpr.dynamic-m.com:8543\/`),<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0 network_id: 80001,<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0 confirmations: 2,<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0 timeoutBlocks: 200,<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0 skipDryRun: true<br \/>\u00a0\u00a0\u00a0 },<br \/>\u00a0 },<\/p>\n<p>\u00a0 <em>\/\/ Set default mocha options here, use special reporters etc.<\/em><br \/>\u00a0 mocha: {<br \/>\u00a0\u00a0\u00a0 <em>\/\/ timeout: 100000<\/em><br \/>\u00a0 },<\/p>\n<p>\u00a0 <em>\/\/ Configure your compilers<\/em><br \/>\u00a0 compilers: {<br \/>\u00a0\u00a0\u00a0 solc: {<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 version: &#8220;0.8.13&#8221;,<br \/>\u00a0\u00a0\u00a0 }<br \/>\u00a0 }<br \/>}<\/p>\n<p>cd ~\/SECRYPT<\/p>\n<p>Note that it requires mnemonic to be passed in for\u00a0sxcProvider. This is the seed phrase (or private key) for the account you would like to deploy from. Create a new\u00a0.secret\u00a0file in the root directory and enter your 12-word mnemonic seed phrase to get started. To get the seed words from Metamask wallet, you can go to MetaMask settings, then from the menu, choose\u00a0Security and Privacy\u00a0where you will see a button that says\u00a0reveal seed words.<\/p>\n<h4><strong>Deploying on SECRYPT Network<\/strong><\/h4>\n<p>Add SXC to your wallet using\u00a0 SECRYPT Faucet. Next, run this command in the root folder of the project directory:<\/p>\n<p>truffle compile<br \/>truffle deploy &#8211;network sxc<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/test.secrypt.tech\/wp-content\/uploads\/2023\/01\/4-968x1024.png\" alt=\"\" width=\"968\" height=\"1024\" \/><\/p>\n<p><b>NOTE<\/b><\/p>\n<p>Remember your\u00a0address,\u00a0transaction_hash\u00a0and other details provided would differ. Above is just to provide an idea of the structure.<\/p>\n<p>Congratulations!\u00a0You have successfully deployed a Smart Contract using Truffle.\u00a0Now you can interact with the contract and also check its deployment status on\u00a0 explorer-testnet.secrypt.tech or explorer-mainnet.secrypt.tech<\/p>\n<p>\u00a0<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Deploy a Smart Contract Using Truffle Overview Truffle\u00a0is a blockchain development environment, which you can use to create and test smart contracts by leveraging the Ethereum Virtual Machine. This guide aims at teaching how to create a smart contract using Truffle and deploying it on the EVM-compatible SECRYPT Network. NOTE This tutorial is an adapted [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"elementor_header_footer","meta":{"site-sidebar-layout":"no-sidebar","site-content-layout":"page-builder","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"disabled","ast-breadcrumbs-content":"","ast-featured-img":"disabled","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"class_list":["post-944","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/test.secrypt.tech\/index.php\/wp-json\/wp\/v2\/pages\/944","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/test.secrypt.tech\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/test.secrypt.tech\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/test.secrypt.tech\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/test.secrypt.tech\/index.php\/wp-json\/wp\/v2\/comments?post=944"}],"version-history":[{"count":13,"href":"https:\/\/test.secrypt.tech\/index.php\/wp-json\/wp\/v2\/pages\/944\/revisions"}],"predecessor-version":[{"id":1414,"href":"https:\/\/test.secrypt.tech\/index.php\/wp-json\/wp\/v2\/pages\/944\/revisions\/1414"}],"wp:attachment":[{"href":"https:\/\/test.secrypt.tech\/index.php\/wp-json\/wp\/v2\/media?parent=944"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}