Contraect interaction

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 contræcts app:

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"));