contraect-maven-plugin
  • Introduction
  • Use the plugin
    • Add dependencies
    • Plugin configuration
    • Plugin execution
      • Error Codes
  • Use the generated classes
    • Contraect interaction
    • Example applications
Powered by GitBook
On this page

Was this helpful?

  1. Use the generated classes

Contraect interaction

PreviousError CodesNextExample applications

Last updated 5 years ago

Was this helpful?

The generated java classes hide all the complexity needed to interact with smart contracts on the aeternity blockchain. The only thing you need to do is create an instance of the generated class and provide an AeternityServiceConfiguration in the constructor.

Without this configuration we wouldn't know to which compiler and to which node we should perform the necessary requests.

For this example we use the CryptoHamster sample from the testnet :

import com.kryptokrauts.aeternity.sdk.constants.Network;
import com.kryptokrauts.aeternity.sdk.constants.VirtualMachine;
import com.kryptokrauts.aeternity.sdk.service.aeternity.AeternityServiceConfiguration;
import com.kryptokrauts.aeternity.sdk.service.aeternity.AeternityServiceFactory;
import com.kryptokrauts.aeternity.sdk.service.aeternity.impl.AeternityService;
import com.kryptokrauts.contracts.CryptoHamster;

AeternityServiceConfiguration config = AeternityServiceConfiguration
				.configure().compilerBaseUrl("http://localhost:3080")
				.baseUrl("http://localhost").baseKeyPair(baseKeyPair)
				.network(Network.DEVNET).targetVM(VirtualMachine.FATE)
				.compile();

// get an instance of the generated contract object				
CryptoHamster cryptoHamsterInstance = new CryptoHamster(config, null);

// deploy the contract on the local node
String contractId = cryptoHamsterInstance.deploy();
System.out.println("Deployed contract id - " + contractId );

// call a function of the contract
System.out.println(cryptoHamsterInstance.createHamster("kryptokrauts"));
System.out.println(cryptoHamsterInstance.nameExists("kryptokrauts"));
System.out.println(cryptoHamsterInstance.getHamsterDNA("kryptokrauts"));
contræcts app