Giter VIP home page Giter VIP logo

sample-project-gradle's Introduction

Web3j: Web3 Java Ethereum Ðapp API

Documentation Status build status codecov Discord

Web3j is a lightweight, highly modular, reactive, type safe Java and Android library for working with Smart Contracts and integrating with clients (nodes) on the Ethereum network:

image

This allows you to work with the Ethereum blockchain, without the additional overhead of having to write your own integration code for the platform.

The Java and the Blockchain talk provides an overview of blockchain, Ethereum and Web3j.

NEW! Get involved!

Since Web3J moved under Hyperledger we started to do Web3J Contributors calls every 2 weeks! Subscribe to our community page and to see check our call schedule. Your contribution matters!

Features

It has five runtime dependencies:

It also uses JavaPoet for generating smart contract wrappers.

QuickStart

The simplest way to start your journey with Web3j is to create a project. We provide this functionality using the Web3j CLI. This latter can be installed as follows:

For Unix:

curl -L get.web3j.io | sh && source ~/.web3j/source.sh

For Windows, in Powershell:

Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/web3j/web3j-installer/master/installer.ps1'))

Create a new project by running:

$ web3j new 

Or use our Maven or Gradle plugins to generate java files from Solidity contracts.

Please head to the Web3j Documentation for further instructions on using Web3j.

Maven

Java:

<dependency>
  <groupId>org.web3j</groupId>
  <artifactId>core</artifactId>
  <version>4.12.0</version>
</dependency>

Note: The Web3j Java binaries are compiled using Java 17. Java 17 or a more recent version is required to use Web3j as a dependency.

Android:

<dependency>
  <groupId>org.web3j</groupId>
  <artifactId>core</artifactId>
  <version>4.8.9-android</version>
</dependency>

Gradle

Java:

implementation ('org.web3j:core:4.12.0')

Android:

implementation ('org.web3j:core:4.8.9-android')

Build instructions

Web3j includes integration tests for running against a live Ethereum client. If you do not have a client running, you can exclude their execution as per the below instructions.

To run a full build (excluding integration tests):

$ ./gradlew check

To run the integration tests, you will need to set up these variables in order to pull the Docker images from the Docker Hub registry:

  • registry.username
  • registry.password

Then run the following command:

$ ./gradlew -Pintegration-tests=true :integration-tests:test

If you do not want the integration test to run:

$ ./gradlew -Pintegration-tests=false :test

Check the Docker client API for more information on configuration options.

Commercial support and training

Commercial support and training is available from web3labs.com.

License

Apache 2.0

sample-project-gradle's People

Contributors

alexandrour avatar conor10 avatar juliozohar avatar kpatel1980 avatar sebaraba avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sample-project-gradle's Issues

android studio

I used Android studio 3.5 to compile this program and promote not module not speicfied,
Can you help me to solve this problem?

insufficient funds for gas * price + value

my ropsten eth : https://ropsten.etherscan.io/address/0x8bCF7803a7CBFB2010456D9040030fFb6754c429


        Web3j web3 = Web3j.build(new HttpService("https://ropsten.infura.io/v3/<project_id>"));

        EthGetBalance balance = web3.ethGetBalance("0x8bCF7803a7CBFB2010456D9040030fFb6754c429", DefaultBlockParameterName.LATEST).send();
        System.out.println(balance.getBalance());
        Credentials creds = Credentials.create("0x8bCF7803a7CBFB2010456D9040030fFb6754c429");
        Demo_sol_GameItem send = Demo_sol_GameItem.deploy(web3, creds, new DefaultGasProvider()).send();
        System.out.println(send.getContractAddress());

Exception in thread "main" java.lang.RuntimeException: java.lang.RuntimeException: Error processing transaction request: insufficient funds for gas * price + value
at org.web3j.tx.Contract.deploy(Contract.java:457)
at org.web3j.tx.Contract.lambda$deployRemoteCall$7(Contract.java:605)
at org.web3j.protocol.core.RemoteCall.send(RemoteCall.java:42)
at com.a.App.main(App.java:36)
Caused by: java.lang.RuntimeException: Error processing transaction request: insufficient funds for gas * price + value
at org.web3j.tx.TransactionManager.processResponse(TransactionManager.java:162)
at org.web3j.tx.TransactionManager.executeTransaction(TransactionManager.java:81)
at org.web3j.tx.ManagedTransaction.send(ManagedTransaction.java:127)
at org.web3j.tx.Contract.executeTransaction(Contract.java:364)
at org.web3j.tx.Contract.create(Contract.java:419)
at org.web3j.tx.Contract.deploy(Contract.java:453)
... 3 more

Unable to execute the sample web3j project

Hi I am trying to run a given sample web3j project in android. But every time I get the following exception.
java.lang.RuntimeException: Error processing transaction request: insufficient funds for gas * price + value

Error processing transaction request: insufficient funds for gas * price + value

Hello, I'm running client
geth --rpcapi personal,db,eth,net,web3 --rpc --rinkeby

server answers: instance=Geth/v1.7.3-stable/linux-amd64/go1.9.4...
importing blocks, no problem.

I fed my account "https://rinkeby.etherscan.io/address/0x03fb8e3666ee5dcc07fc74c85d26f0fd952e39e1"

But every time I'm trying to run sample.java i'm getting this error:

Connected to Ethereum client version: Geth/v1.7.3-stable/linux-amd64/go1.9.4
Credentials loaded
Sending 1 Wei (0.000000000000000001 Ether)
Exception in thread "main" java.lang.RuntimeException: Error processing transaction request: insufficient funds for gas * price + value
at org.web3j.tx.TransactionManager.processResponse(TransactionManager.java:67)
at org.web3j.tx.TransactionManager.executeTransaction(TransactionManager.java:51)
at org.web3j.tx.ManagedTransaction.send(ManagedTransaction.java:70)
at org.web3j.tx.Transfer.send(Transfer.java:65)
at org.web3j.tx.Transfer.send(Transfer.java:49)
at org.web3j.tx.Transfer.lambda$sendFunds$20(Transfer.java:76)
at org.web3j.protocol.core.RemoteCall.send(RemoteCall.java:30)
at org.web3j.sample.Application.run(Application.java:81)
at org.web3j.sample.Application.main(Application.java:55)

compile solidity error

download solc and put in the root directory of project .
then command run grandlew.bat build then show error:
Error: Source file requires different compiler version (current compiler is 0.5.10+commit.5a6ea5b1.Windows.msvc - note that nightly builds are considered to be strictly less than the released version
pragma solidity ^0.4.25;

change the pragma solidity >0.4.25 then get more errors.
please update solidity file.

Could not resolve org.ethereum:solcJ-all:0.4.25.

Hi, I met an error at loading Gradle changes, and I didn't modify any of the code.

`
A problem occurred configuring root project 'sample-project-gradle'.

Failed to notify project evaluation listener.
Could not resolve all files for configuration ':compileClasspath'.
> Could not resolve org.ethereum:solcJ-all:0.4.25.
Required by:
project :
> Could not resolve org.ethereum:solcJ-all:0.4.25.
> Could not get resource 'https://dl.bintray.com/ethereum/maven/org/ethereum/solcJ-all/0.4.25/solcJ-all-0.4.25.pom'.
> Could not GET 'https://dl.bintray.com/ethereum/maven/org/ethereum/solcJ-all/0.4.25/solcJ-all-0.4.25.pom'. Received status code 403 from server: Forbidden
Task with name 'compileSolidity' not found in root project 'sample-project-gradle'.

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
    `

Issues and solutions I've taken

Foreword: many issues can be fixed by applying certain steps from the Getting Started guide.

  1. No Greeter.java (wrapper code)
    Solution:
  • Download Solicity compiler (check the .sol file for version, currently 0.4.25 is needed for the file) and web3j cli.
  • Follow this guide to generate the Java code you need
  1. Cannot resolve 'ethLogFlowable'
    Solution: add into build.gradle
  • compile ('org.web3j:core:4.1.0') (Java 8)
  • compile ('org.web3j:core:4.1.0-android') (Android)
  1. RxJava dependency missing
    Solution: add into build.gradle
  • implementation "io.reactivex.rxjava2:rxjava:2.x.y"
    With x and y replaced by the version number found here.

File Path Query?

23:37:29.041 [main] INFO org.web3j.sample.Application - Please enter your wallet file path
----------------------------?
23:38:45.511 [main] INFO org.web3j.sample.Application - Enter password
----------------------------?

solc. finished with non-zero exit value 1

I am using this sample app to experiment with my own contracts. My own contracts require solidity compiler 0.5.0+, so I've changed the gradle file to set the solidty version correspondingly.

pragma solidity ^0.5.0;
contract XXX {...}

web3j {
    ...
    solidity {
        version = '0.5.0'
    }
}

When I start the gradle build I always get the following error:
Execution failed for task ':compileSolidity'.

Process 'command '/var/folders/4d/rwvvzqh10nx5x9qg3yw8jsz00000gn/T/solc/solc'' finished with non-zero exit value 1

If I set pragma to
pragma solidity ^0.4.0;

it works. It seems to me the build process is not respecting the solidity version set.

Getting org.bouncycastle.jce.provider Exception

it is working well in my localhost but when deployed to server it throws following exception.

java.lang.ClassCastException: org.bouncycastle.jce.provider.JCEECPrivateKey cannot be cast to org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPrivateKey

SSL peer shut down incorrectly

There is an issue during the first import of the project.

SSL peer shut down incorrectly

The same has happened when I add id 'org.web3j' version '4.6.0' to my project. During work on this issue for adding plugin into my project I reach the point where I need to tell server to use old version of TLS, but I have not been managed to make it work.

`Gradle 7.3.3

Build time: 2021-12-22 12:37:54 UTC
Revision: 6f556c80f945dc54b50e0be633da6c62dbe8dc71

Kotlin: 1.5.31
Groovy: 3.0.9
Ant: Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM: 16.0.1 (Oracle Corporation 16.0.1+9-24)
OS: Linux 5.4.0-126-generic amd64
`

Sample contract is not deployed. Not enough gas

Transfer transaction works OK, but deploy fails. What's wrong?
Source code:
ContractGasProvider contractGasProvider = new DefaultGasProvider();
try {

        contract = Greeter.deploy(
                web3j, credentials,
                contractGasProvider,
                "Hello!"
        ).send();
        contractAddress  = contract.getContractAddress();
        System.out.printf("Contract Address : " + contract.getContractAddress());
    } catch(Exception e){
        e.printStackTrace();
    }

08:34:34.908 [main] INFO org.web3j.sample.Application - Deploying smart contract
org.web3j.protocol.exceptions.TransactionException: Transaction has failed with status: 0x0. Gas used: 4300000. (not-enough gas?)
at org.web3j.tx.Contract.executeTransaction(Contract.java:290)
at org.web3j.tx.Contract.create(Contract.java:326)
at org.web3j.tx.Contract.deploy(Contract.java:355)
at org.web3j.tx.Contract.lambda$deployRemoteCall$7(Contract.java:449)
at org.web3j.protocol.core.RemoteCall.send(RemoteCall.java:30)
at org.web3j.sample.Application.run(Application.java:124)
at org.web3j.sample.Application.main(Application.java:67)
Exception in thread "main" java.lang.NullPointerException
at org.web3j.sample.Application.run(Application.java:144)
at org.web3j.sample.Application.main(Application.java:67)
Disconnected from the target VM, address: '127.0.0.1:62773', transport: 'socket'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.