package com.yourcompany.web3.apps; // Super important: Our app uses the generated Java from solc! import com.yourcompany.web3.generated.TheContract; import java.math.BigInteger; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.web3j.crypto.Credentials; import org.web3j.crypto.WalletUtils; import org.web3j.protocol.Web3j; import org.web3j.protocol.http.HttpService; import org.web3j.tx.Contract; // for GAS_LIMIT constant import org.web3j.tx.ManagedTransaction; // GAS_PRICE constant public class deploy1 { private static final Logger log = LoggerFactory.getLogger(deploy1.class); public static void main(String[] args) throws Exception { new deploy1().run(); } private void run() { try { // This is the geth dev server you are running. Note: NOT https! String MY_CONN_URL = "http://127.0.0.1:8545"; // This is the developer wallet autocreated and funded by the --dev option. // There should be only one file in the keystore directory; use that one. // The actual name will be different than this. Again, the point of using // --datadir with the --dev option is that this resource will be created // just once and you don't have to keep finding a new wallet file and // change the program: String MY_WALLET_FILE = "yourhome/eth/dev/data/keystore/UTC--2020-08-30T15-35-42.179527700Z--ad2a9bde6c3fe0149c29db01ed40966b1b06f3d0"; String MY_WALLET_PWD = ""; // IMPORTANT! The password for the geth --dev developer account wallet is BLANK! System.out.println("Connecting to " + MY_CONN_URL); Web3j web3j = Web3j.build(new HttpService(MY_CONN_URL)); System.out.println("Loading credentials..."); Credentials credentials = WalletUtils.loadCredentials(MY_WALLET_PWD, MY_WALLET_FILE); System.out.println("Deploying smart contract; be patient..."); TheContract contract = TheContract.deploy( // These first 4 args are always the same types: web3j, credentials, ManagedTransaction.GAS_PRICE, Contract.GAS_LIMIT, // The next are the required args for the constructor() of the smart contract! // OR no additional args if the constructor has no args. "CPTY1".getBytes(), // notice: we pass byte[], not String new BigInteger("1000") // ... and ALL uint types go in (and out) as BigInteger ).send(); String contractAddress = contract.getContractAddress(); System.out.println("Contract address: " + contractAddress); web3j.shutdown(); } catch(Exception e) { System.out.println("exception: " + e); } } }