# Smart Contract

### Calling smart contract

There are two types of smart contract calls: *const call* and *trigger call*.

Simply, a ***const call*** returns result immediately once and no need to sign or broadcast.

***Trigger call*** is a type of system contract call, needs signing and broadcasting. It fetches the result through the API.

You may see the functions of a specified contract by `ContractFunction.toString()`, then you can construct a `Function` object to make a constant/trigger call.

#### Get contract

Get a Contract object from the address.

**PARAMS**

*1. contractAddress(String)*

The address of a smart contract.

**RETURN**

A Contract object.

**THROW**

Throws if the given contract address does not match any.

**Example** : &#x20;

```
public void getSmartContract() {
        try {
            AixcClient client = new AixcClient("172.104.51.182:16669","172.104.51.182:16669","private key");
            Contract cntr = client.getContract("AV27cVbuGmTv9q6qgtPxsLUkuG9ohUUVPd"); //JST
             for (ContractFunction cf : cntr.getFunctions()) {
                System.out.println(cf.toString());
            }
        } catch (Exception e) {
            System.out.println("error: " + e);
        }
    }
```

The result is:

```
Contract name: ARC721Token
cntr.getOriginAddr()
<ByteString@2ce86164 size=21 contents="AB\003HZSZ@r\311\373\372\255\337\342\240\020\255\v\315\260">
Contract functions: []
```

#### Trigger call

Make a trigger call. Trigger calls require signature and broadcasting. Refer to RPC\_APIs for the signing and broadcasting functions.

The first half of the *trigger call* process is similar to the *const call*.

You can easily set **feeLimit**, **`memo`** and other common attributes via the **TransactionBuilder**

**PARAMS**

*1. ownerAddr(String)*\*

The caller’s address.

*2. contractAddr(String)*\*

The contract’s address.

*3. function(Function)*\*

The exact function you are calling, you can find the example in the `triggerCallDemo`.

**RETURN**

A TransactionBuilder object, for easily setting memos, feelimit, Etc.

**THROW**

Throws if the function does not match any in the smart contract.

**Example:**

```
publ public void triggerCallDemo() {
        AixClient client = new AixcClient("172.104.51.182:16669","172.104.51.182:16669","private key");
        try {
            //function 'setApprovalForAll'
            //params: function name, function params
            Function arc721Transfer = new Function("setApprovalForAll",
                    Arrays.asList(new Address("41a9c46373aEB4749E3CE45acA242b027A46f486f9"),
                            new Bool(false)),
                    Arrays.asList(new TypeReference<Bool>() {}));

            //the params are: owner address, contract address, function
            TransactionBuilder builder = client.triggerCall("414203485a535a4072C9FBFaADDfe2A010AD0BcdB0", "WV27cVbuGmTv9q6qgtPxsLUkuG9ohUUVPd", wrc721Transfer); //JST
            //set extra params
            builder.setFeeLimit(100000000L);
            builder.setMemo("Let's go!");
            //sign transaction
            Transaction signedTxn = client.signTransaction(builder.build());
            System.out.println(signedTxn.toString());
            //broadcast transaction
            String ret = client.broadcastTransaction(signedTxn);
            System.out.println("======== Result ========\n" + ret);
        } catch (Exception e) {
            System.out.println("error: " + e);
        }
    }

```

\======== Result ======== 0d2b6a4a7d52e0775da63443e285010441ab9490cf57c47c097ff85b79aff3e0

#### constantCall

Make a constant call, without broadcasting.

**PARAMS**

*1. ownerAddr(String)*\*

The caller’s address.

*2. contractAddr(String)*\*

The contract’s address.

*3. function(Function)*\*

The exact function you are calling, you can find the example in the `triggerCallDemo`.

**RETURN**

A TransactionExtention object

**THROW**

Throws if the function does not match any in the smart contract.

<br>
