Call
Calls to a contract can either be simple calls, or contract transactions. Calls do not necessarily incur a cost, but contract transactions always incur a cost as they are changing the state of the blockchain. Calls to a contract will always return something, whereas contract transaction may not depending on the function called.
Interact with a deployed contract: mvn aion4j:call
Local
To call a function from a deployed contract on a local node, run the following command:
For example:
The -Dmethod argument controls which function is called within the HelloWorld.java contract. In this case, we called the greet function.
The -Dargs argument controls variables we want to supply to the method. If no variables are required by the function, then you do not need to include this argument. Multiple variables can be supplied between double quotes ". In this case, we have supplied the string Bob. Check out the Variable Types page for more information.
Remote
In order to call a contract on a remote node you must have:
- The contract
address. - The
addressof the account you want to use to call the contract. This is not the same as the contract address. - The URL of the
hostremote node you want to connect to. a. You may also need theportnumber of the node. This isn’t always necessary when using a node hosting service. - The
functionname you want to call from the contract. - Any
argumentsthat you want to supply to the function.
Run the following to call a function in a contract on a remote node:
For example:
Supplying Arguments
Arguments can be supplied when calling a function by adding the -Dargs tag and entering the required types and variables. For example:
Calling a Specific Contract
You do not have to supply a contract address because the Aion4j plugin caches the last deployed contract address. However, if you want to call a specific contract then you can supply the contract address using the -Daddress tag:
Make sure to add -Premote to the command when calling a remote node.