Skip to content

Latest commit

 

History

History
executable file
·
78 lines (47 loc) · 2.68 KB

README.md

File metadata and controls

executable file
·
78 lines (47 loc) · 2.68 KB

IC4J Management Java Service

This Java library is an implementation of Dfinity's Virtual Canister Management API and directly communicates with the Management Virtual Canister.

https://internetcomputer.org/docs/current/references/ic-interface-spec#ic-management-canister

Developers can utilize this library within any Java application to perform various operations, such as creating, deleting, starting, and stopping a canister, installing, uninstalling, and reinstalling WASM canister code, updating canister settings, and adding additional funds to a canister.

To test Management Service locally, install local Internet Computer instance. Then just configure custom Java properties with management.location value pointing to the local instance and management.identity pointing to identity PEM file.

To use Management Service create ManagementService object. Define your own properties if you want to use local instance of the service.

Identity identity = BasicIdentity.fromPEMFile(sourceReader);

Agent agent = new AgentBuilder().transport(transport)
			.identity(identity)
			.build();

ManagementService managementService = ManagementService.create(agent);

Then call Management Service methods.

Principal canisterId = managementService.provisionalCreateCanisterWithCycles(Optional.empty(), Optional.empty()).get();

LOG.info(canisterId.toString());
			
Path path = Paths.get(getClass().getClassLoader().getResource(WASM_FILE).getPath());
			
byte [] wasmModule = Files.readAllBytes(path);	
			
managementService.installCode(canisterId, Mode.install, wasmModule, ArrayUtils.EMPTY_BYTE_ARRAY);
			
CanisterStatusResponse canisterStatusResponse =  managementService.canisterStatus(canisterId).get();
			
LOG.info(canisterStatusResponse.status.name());						
			
managementService.stopCanister(canisterId);	
			
canisterStatusResponse =  managementService.canisterStatus(canisterId).get();
			
LOG.info(canisterStatusResponse.status.name());		
			
managementService.uninstallCode(canisterId);			

managementService.deleteCanister(canisterId);

Downloads / Accessing Binaries

To add Java IC4J Management Service library to your Java project use Maven or Gradle import from Maven Central.

https://search.maven.org/artifact/ic4j/ic4j-management/0.6.19.7/jar
<dependency>
  <groupId>org.ic4j</groupId>
  <artifactId>ic4j-management</artifactId>
  <version>0.6.19.7</version>
</dependency>
implementation 'org.ic4j:ic4j-management:0.6.19.7'

Build

You need JDK 8+ to build IC4J Management Service.