cover-img

COMPILING THE SMART CONTRACTS

There are many ways one can convert smart contract into ABI or BYTECODE. We will look at by using one of the framework and using IDE.

12 July, 2022

4

4

0

You can read more about ABI and BYTECODE here πŸ‘‡

'understanding-smart-contract-bytecode-and-abi'

LETS START.....

πŸ’œ Recap

  • In the previous article we learnt that EVM requires ABI and BYTECODE to understand any smart contract.
  • ABI gives the power to interact with Smart Contract using JavaScript
  • BYTECODE gives commands for EVM on how to execute the Smart Contract.

if you want to understand in more depth, Please read my last article.

πŸ’œ Converting to ABI and BYTECODE

  • There are many framework through which we can convert Smart Contract into ABI and BYTECODE. Among them we will look into few of them.
  • Before that we will need smart contract to convert. So, Copy the below code into VS code or any IDE as per your preference and follow along.

SMART CONTRACT

  • Create a file named "SimpleSmartContract.sol".
  • .sol is an extension used for solidity files.
  • This Smart Contract is very simple, It updates a number, gets the number and multiply it with a number.

πŸ‘‰ Remember, There are many extensions for Solidity in VS code. You can use anyone for proper intellisense and linting. Just search solidity in extension marketplace.

πŸ’œ SOLCJS

  • Its a framework written in typescript and can provide ABI and BYTECODE with single command.
  • we have to install it using npm or yarn and for npm we need 'Node.js'. So first install Node.js if not installed.
  • Open any terminal and change the directory to the location where smart contract is stored.
  • Using NPM

  • or We can also use YARN

  • To check if solc is installed , write

if no error, then solc is installed else we need to install it again. Check location of terminal pointing to.

To compile , we use this command :


πŸ‘‰ SimpleSmartContract.sol is the name of the smart contract. Replace it with the name of your own smart contract.

πŸ‘‰ --bin and --abi tells the solcjs to create .bin as well as .abi file. If you need anyone then simply remove the other one from the command.

πŸ’œ BYTECODE


πŸ’œ ABI


πŸ‘‰ Remember if you want to read ABI, just change the extension from .abi to .json, The file will update and then change it back to .abi again.

  • You can read more about solcjs here πŸ‘‰ 'solcJs'

πŸ’œ REMIX IDE

  • Remix IDE allows developing, deploying and administering smart contracts for Ethereum like blockchains.
  • You can visit it here πŸ‘‰REMIX IDE
  • Create a new file and name it "SimpleSmartContract.sol" and paste the smart contract as shown.

Screenshot 2022-07-12 211011.png

πŸ‘‰ Make sure that compiler version is set to ^0.8.7. You can set it by clicking on Solidity Compiler button at most left panel. Select Compiler from dropdown as 0.8.7+commit.. In the Smart Contract we have defined compiler version, Its best to pick the same compiler version as in Smart Contract.

Screenshot 2022-07-12 211011.png

  • After pasting the code, we can hit compile button and check if any errors. If any error Please check that compiler version is correct.
  • Below that Solidity Compiler, We have Deploy & Run Transaction. Select it. Keep the option as it is.

Screenshot 2022-07-12 211011.png

  • We hit Deploy button.
  • We can see our smart contract deploy as shown below.

Screenshot 2022-07-12 211011.png

  • Now In the Compiler tab, we can see ABI & BYTECODE button. From there one can copy the ABI/BYTECODE and have a look at it.

Screenshot 2022-07-12 213845.png

These are the ways one can convert the Smart Contract to ABI and BYTECODE.

πŸ‘‰ Remember the BYTECODE and ABI will be same for same Smart Contract. It will never be different irrespective of the method of conversion. It will only change if Smart Contract changes.

In the next article, we will see basics of solidity and how to write smart contract and deploy it.

4

4

0

Tanisk Annpurna
I love making changes that touches people's πŸ’ž | Software Developer | Web3 Enthusiast

More Articles

Showwcase is a professional tech network with over 0 users from over 150 countries. We assist tech professionals in showcasing their unique skills through dedicated profiles and connect them with top global companies for career opportunities.

Β© Copyright 2025. Showcase Creators Inc. All rights reserved.