org.web3j.tx.ManagedTransaction Java Examples

The following examples show how to use org.web3j.tx.ManagedTransaction. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Web3Service.java    From tutorials with MIT License 6 votes vote down vote up
public String fromScratchContractExample() {

        String contractAddress = "";

        try {
            //Create a wallet
            WalletUtils.generateNewWalletFile("PASSWORD", new File("/path/to/destination"), true);
            //Load the credentials from it
            Credentials credentials = WalletUtils.loadCredentials("PASSWORD", "/path/to/walletfile");

            //Deploy contract to address specified by wallet
            Example contract = Example.deploy(this.web3j,
                    credentials,
                    ManagedTransaction.GAS_PRICE,
                    Contract.GAS_LIMIT).send();

            //Het the address
            contractAddress = contract.getContractAddress();

        } catch (Exception ex) {
            System.out.println(PLEASE_SUPPLY_REAL_DATA);
            return PLEASE_SUPPLY_REAL_DATA;
        }
        return contractAddress;
    }
 
Example #2
Source File: Template.java    From tutorials with MIT License 6 votes vote down vote up
private void deployContract() throws Exception{

        Web3j web3j = Web3j.build(new HttpService("https://rinkeby.infura.io/<your_token>"));

        Credentials credentials =
            WalletUtils.loadCredentials(
               "<password>",
               "/path/to/<walletfile>");

        Greeting contract = Greeting.deploy(
            web3j, credentials,
            ManagedTransaction.GAS_PRICE, Contract.GAS_LIMIT,
            "Hello blockchain world!").send();

        String contractAddress = contract.getContractAddress();
        l.debug("Smart contract deployed to address "+ contractAddress);

        l.debug("Value stored in remote smart contract: "+ contract.greet().send());

        TransactionReceipt transactionReceipt = contract.setGreeting("Well hello again").send();

        l.debug("New value stored in remote smart contract: "+ contract.greet().send());
    }