IC4J API Docs
  • Overview
    • Introduction
  • Quick Start
  • License
  • Reference
    • API Reference
      • Install IC4J Libraries
      • Supported Types
      • ReplicaTransport
      • Identity
      • Principal
      • AgentBuilder
      • ProxyBuilder
      • Using IDLArgs
      • QueryBuilder and UpdateBuilder
      • Using Raw Agent Methods
      • Handle Binary Payloads
      • Object Serializers and Deserializers
        • Pojo Serializer and Deserializer
        • JSON Jackson Serializer and Deserializer
        • JSON Gson Serializer and Deserializer
        • XML DOM Serializer and Deserializer
        • XML JAXB Serializer and Deserializer
        • JDBC Serializer
      • Android Development
Powered by GitBook
On this page
  • QueryBuilder
  • UpdateBuilder
  1. Reference
  2. API Reference

QueryBuilder and UpdateBuilder

PreviousUsing IDLArgsNextUsing Raw Agent Methods

Last updated 1 year ago

Another option to call the Internet Computer canisters from Java is to use QueryBuilder and UpdateBuilder.

Use these options if direct manipulation with Candid data is required or there is a requirement for dynamic invocation.

Create byte[] array binary Candid payload as an input argument using .

List<IDLValue> args = new ArrayList<IDLValue>();
BigInteger intValue = new BigInteger("10000");
args.add(IDLValue.create(intValue));
IDLArgs idlArgs = IDLArgs.create(args);
byte[] payload = idlArgs.toBytes();

QueryBuilder

Method create has 3 arguments, agent, canister id principal and method name.

Optionally, the expiration time can be set using Methods expireAfter or expireAt.

Pass binary payload as a parameter of arg method and execute using Method call.

CompletableFuture<byte[]> response = QueryBuilder
	.create(agent, Principal.fromString(canisterid), "echoInt")
	.expireAfter(Duration.ofMinutes(3))
	.arg(payload)
	.call();

UpdateBuilder

CompletableFuture<byte[]> response = UpdateBuilder
	.create(agent, Principal.fromString(canisterid), "greet")
	.expireAfter(Duration.ofMinutes(3))
	.arg(payload)
	.callAndWait(Waiter.create(60, 5));

Use this to convert response payload to Java objects from binary Candid response payload.

byte[] output = response.get();
IDLArgs outArgs = IDLArgs.fromBytes(output);

uses very similar syntax to Method create, but has one extra method, callAndWait ,if explicit definition is required.

IDLArgs
QueryBuilder
UpdateBuilder
Waiter