🧇Truffle
Deploy and test a smart contract on Gitshock Chain using Truffle
What is Truffle?
A world class development environment, testing framework and asset pipeline for blockchains using the Ethereum Virtual Machine (EVM), aiming to make life as a developer easier.
Requirements
You've familiar with Gitshock's or Ethereum architecture
Dependencies
Windows, Linux, or macOS
Install Node.js
Note: to install the latest version of npm
, run npm i -g npm
Install Truffle
Warning: Avoid using the
sudo
command when installing Truffle, this can cause permission errors.
You may receive a list of warnings during installation. To confirm that Truffle was installed correctly, run:
Install Web3.js
Create Truffle Directory
Open a new terminal tab to so we can create a truffle
directory and install some further dependencies.
First, navigate to the directory within which you intend to create your truffle
working directory:
cd /path/to/directory
Download the MetaCoin box:
With that last step, you have created a Truffle project cointaining folders with contracts, deployment, testing, and configuration files.
This is the smart contract data from the metacoin.sol
file:
Note Notice that ConvertLib is being imported just after the
pragma
statement. 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.
Testing the Contract
You can run Solidity and Javascript tests.
In a terminal, run the Solidity test:
You should see the following output:
Run the JavaScript test:
You should see the following output:
Compiling the Contract
Compile the smart contract using the following command:
Configuring the Smart Contract
Before actually depolying the contract, you need to set up the truffle-config.js
file, inserting network and compilers data.
Go to truffle-config.js
and update the file with Gitshock Chain network details.
Note Note that it requires mnemonic to be passed in for gitshock providers. This is the seed phrase (or private key) for the account you would like to deploy from. Create a new .secret file 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 Security and Privacy where you will see a button that says reveal seed words.
Deploying on Gitshock Chain
Add GTFX to your wallet using Gitshock Faucet. Next, run this command in the root folder of the project directory:
Note Remember your
address
,transaction_hash
and other details provided would differ. Above is just to provide an idea of the structure. # You can find repo starter Smart Contract in here : https://github.com/gitshock-labs/smartcontract-starter
Congratulations! You have successfully deployed a Smart Contract using Truffle. Now you can interact with the contract and also check its deployment status on Gitshock Scan.
Last updated