By using this site, you agree to the Privacy Policy and Terms of Use.
Accept
KriptotekaKriptoteka
  • Home
  • News
    • Web3
    • Crypto News
    • Market Analysis
  • Market
    • AI
    • Altcoins
    • Bitcoin
    • Blockchain
    • CEX
    • Defi
    • DePIN
    • DEX
    • ETFs
    • Ethereum
    • Gaming
    • ICO/IDO
    • Institutions
    • L1&L2
    • Meme
    • NFT tech
    • RWA
    • Stable coins
  • Data
  • Events
  • Learn
  • Reports
  • Podcasts
  • Pro membership
Reading: New Features in Web3j-Solidity Gradle Plugin for Compilation
Share
Notification Show More
Font ResizerAa
Font ResizerAa
KriptotekaKriptoteka
  • Home
  • News
  • Market
  • Data
  • Events
  • Learn
  • Reports
  • Podcasts
  • Pro membership
  • Home
  • News
    • Web3
    • Crypto News
    • Market Analysis
  • Market
    • AI
    • Altcoins
    • Bitcoin
    • Blockchain
    • CEX
    • Defi
    • DePIN
    • DEX
    • ETFs
    • Ethereum
    • Gaming
    • ICO/IDO
    • Institutions
    • L1&L2
    • Meme
    • NFT tech
    • RWA
    • Stable coins
  • Data
  • Events
  • Learn
  • Reports
  • Podcasts
  • Pro membership
Have an existing account? Sign In
Follow US
  • Advertise
© 2022 Foxiz News Network. Ruby Design Company. All Rights Reserved.
Kriptoteka > Web3 > New Features in Web3j-Solidity Gradle Plugin for Compilation
Web3

New Features in Web3j-Solidity Gradle Plugin for Compilation

marcel.mihalic@gmail.com
Last updated: September 9, 2024 5:20 am
By marcel.mihalic@gmail.com 5 Min Read
Share
SHARE

What is the web3j-solidity-gradle plugin?

The web3j-solidity-gradle-plugin is a useful extension of the web3j library, designed to facilitate the integration of Solidity smart contract compilation into your Gradle project. It streamlines the process of constructing and managing smart contracts within a Java or Android project utilizing Web3j. The plugin provides various configurations for compilation and uses web3j-sokt in the background.

Web3j-Sokt is a Kotlin wrapper for the Solidity compiler (solc). It analyzes Solidity files, determining the appropriate compiler version based on the pragma statement at the file’s beginning. It can then download, install, and invoke the compiler. Unlike Dockerized versions of Solc, Sokt relies on native builds, supporting compatibility across Mac, Windows, and Linux platforms.

For additional details on web3j-sokt, visit: https://github.com/hyperledger/web3j-sokt

How to utilize the web3j-solidity-gradle plugin?

Step 1: Apply the Plugin

Begin by applying the web3j-solidity-gradle plugin to your Gradle project. You can accomplish this by incorporating the following lines into your build.gradle file:

plugins {
    id 'org.web3j.solidity.gradle.plugin' version 'x.y.z' 
}

Step 2: Configure the Plugin

Once the plugin is applied, you can configure the compilation parameters. Below is a sample configuration:

solidity {
    // Optional: Specify the Solidity compiler version
    solcVersion = 'v0.5.16' 

    // Optional: Configure the optimizer
outputComponents = [BIN, ABI, ASM_JSON]
        optimizeRuns = 500
}

Step 3: Include Solidity Files

Naturally, all .sol files located in $projectDir/src/main/solidity and $projectDir/src/test/solidity will be handled by the plugin. To define and add alternative source sets, utilize the sourceSets DSL. It’s also possible to establish your desired output directory for the compiled code.

sourceSets {
    main {
        solidity {
            srcDir {
                "my/custom/path/to/solidity"
             }
             output.resourcesDir = file('out/bin/compiledSol') 
        }
    }
}

Step 4: Compile Contracts

To compile your Solidity contracts, execute the following command in your terminal:

./gradlew build

Alternatively, you may run the compileSolidity gradle task directly:

./gradlew compileSolidity

This command initiates the compilation of Solidity contracts, generating binary and ABI files in the specified output directory.

Step 5: Integrate with Web3j

Once your contracts are compiled, you may wish to create Java wrappers for interaction. You can include the web3j library in your project and leverage the Web3j CLI or Web3j Gradle plugin to generate these wrappers. Here’s a guide on how to add the Web3j-gradle-plugin to your Gradle project: https://docs.web3j.io/4.11.0/plugins/web3j_gradle_plugin/

You can then utilize the plugin to generate Java wrappers corresponding to your smart contracts.

Step 6: Execute and Test

Ultimately, employ the generated Java wrappers in your Java or Android project to deploy, interact with, and test your smart contracts.

Introducing New Features in the Web3j-Solidity-Gradle Plugin

The Web3j Solidity Gradle plugin supports defining multiple source sets. However, the Solidity compilation configuration remains global, meaning it cannot be uniquely set per source set.

Below is an example of how source sets along with Solidity flags are currently set up:

sourceSets {
    main {
        solidity {
            srcDir {
                "my/custom/path/to/solidity"
            }
            output.resourcesDir = file('out/bin/compiledSol') 
        }
    }
}

solidity {
    outputComponents = [BIN, ABI, ASM_JSON]
    optimizeRuns = 500
}

This setup can present challenges for users seeking distinct configurations for compiling smart contracts across multiple source sets since compilation settings are restricted to global values.

To tackle this issue, we’ve rolled out new features that allow users to configure parameters such as Solidity version, EVM version, optimization settings, and optimization runs on a per-source-set basis.

An example utilizing the new functionality:

sourceSets {
    main {
        solidity {
            srcDir {
                "my/custom/path/to/solidity"
            }
            output.resourcesDir = file('out/bin/compiledSol')
            setEvmVersion('ISTANBUL')
            setOptimize(true)
            setOptimizeRuns(200)
            setVersion('0.8.12')
        }
    }
}

Developers interested in exploring this new feature set can follow the related pull request: https://github.com/hyperledger/web3j-solidity-gradle-plugin/pull/69. These capabilities will be presented in the anticipated release of the Web3j-Solidity-Gradle plugin v0.4.2.

Users and developers can access the project source code here – https://github.com/hyperledger/web3j-solidity-gradle-plugin

 

The Web3j-Solidity-Gradle plugin delivers a cohesive development experience, bridging the gap from smart contract coding to Java application integration. The newly introduced features enable users to apply distinct compilation settings for smart contracts across various source sets, enhancing the management of project-specific requirements.

 

Contents
What is the web3j-solidity-gradle plugin?How to utilize the web3j-solidity-gradle plugin?Introducing New Features in the Web3j-Solidity-Gradle Plugin

You Might Also Like

Checksum Verification in Web3j: Protecting Against Attacks

Linea ENS Integration in Hyperledger Web3j for Developers

Run an RPC Node on Base with Moralis: A Step-by-Step Guide[embed]https://www.youtube.com/watch?v=G3sNXEls0HA[/embed]

Moralis Expands with Full Support for Linea Layer-2 Solution

Moralis Unveils Enhanced Wallet API with New DeFi Positions

Share This Article
Facebook Twitter Email Print
Previous Article N. Korea’s ‘Aggressive’ Cyber Attacks on Crypto Industry Revealed
Next Article Dogecoin Bulls Target $0.10: Can They Break Through?
Leave a comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Stay Connected

FacebookLike
TwitterFollow
YoutubeSubscribe
TelegramFollow
- Advertisement -
Ad image

Latest News

4 Cryptos to Challenge Solana: Potential Growth for Investors
Defi
Bitcoin ETF Inflows Exceed $3B, Demand Reaches 6-Month Peak
ETFs
Japan’s Push for Bitcoin and Ethereum ETFs Gains Momentum
Institutions
Ripple Appeals Court Ruling on XRP’s Institutional Sales
Meme
//

We influence millions of users and is the number one Crypto and Web3 news network on the planet

Sign Up for Our Newsletter

Subscribe to our newsletter to get our newest articles instantly!

© 2022 Foxiz News Network. Ruby Design Company. All Rights Reserved.
Join Us!

Subscribe to our newsletter and never miss our latest news, podcasts etc..

Zero spam, Unsubscribe at any time.
Welcome Back!

Sign in to your account

Lost your password?