Web3J not working

Hi, i try do transaction to a smart contract but i recived this error: java.lang.NoSuchMethodError: 'okhttp3.RequestBody okhttp3.RequestBody.create(java.lang.String, okhttp3.MediaType) `rideeditado=this.rideService.guardarRide(ride);

System.out.println("Connecting to Ethereum ...");
			    Web3j web3 = Web3j.build(new HttpService("https://rinkeby.infura.io/v3/9e71d2450c4b42ea9dd3f6d40f239ffe"));
			    System.out.println("Successfuly connected to Ethereum");

			    
			    	String pk = "0xcf9833c6b3DBb19F16De86107D8319156e602614";
			    	Credentials credentials = Credentials.create(pk);

			    	// Contract and functions
			    	String contractAddress ="0xC68E07C25Bef3c84db763e24DdD9F1D57cB76aa5";
			    	
			    	
			    	
			    	Function function = new Function("set", // Function name
			    			Arrays.asList(new Uint(BigInteger.valueOf(20))), // Function input parameters
			    	    Collections.emptyList()); // Function returned parameters

			    	//Encode function values in transaction data format
			    	String txData = FunctionEncoder.encode(function);

			    	// RawTransactionManager use a wallet (credential) to create and sign transaction 
			    	TransactionManager txManager = new RawTransactionManager(web3, credentials);

			    	// Send transaction
			    	String txHash = txManager.sendTransaction(
			    	    DefaultGasProvider.GAS_PRICE, 
			    	    DefaultGasProvider.GAS_LIMIT, 
			    	    contractAddress, 
			    	    txData, 
			    	    BigInteger.ZERO).getTransactionHash();

			    	
			    	// Wait for transaction to be mined
			    	 
			    	TransactionReceiptProcessor receiptProcessor = new PollingTransactionReceiptProcessor(web3, 
			    	    TransactionManager.DEFAULT_POLLING_FREQUENCY, 
			    	    TransactionManager.DEFAULT_POLLING_ATTEMPTS_PER_TX_HASH);
			    	TransactionReceipt txReceipt = receiptProcessor.waitForTransactionReceipt(txHash);`
1 Like

Hi @Alvaro_BF,

I’d suggest looking at the links from this similar community thread from the other day. If these don’t work, please let us know and we’ll see what other resources we can find!

1 Like