4.6 Interact with a smart contract

Once you have uploaded and deployed or linked a smart contract you can then interact with it through either the UI or the API. We can divide the interaction into two categories of attributes: Read values and Write values.

Read values do not incur a transaction cost and can generally be read from the blockchain without the need for a wallet.

Write values are attributes that require the correct composition, signing, and submission of a transaction to the blockchain.

From the UI you can select Contracts > Contracts from the main menu then click on one of the uploaded contracts. There are then two ways to reach an instance contract:

  • Select an instance from the side menu under the contract name or
  • Select an instance in the Contract address dropdown under the name in the contract window

Read Values: "Details"

Read values are read-only methods and publicly exposed variables in the contract. In the UI, read values are automatically queried and displayed on the Details section on the contract page.

To query a read only property you can make a POST request like the following.

Request
POST .../chains/ethereum/addresses/curvetoken/contracts/mltitoken/methods/totalSupply
Response
{
  "status": 200,
  "message": "success",
  "result": {
    "output": "999.000",
    "summarizedInputs": []
  }
}

Even though the function does not modify the blockchain state, we use a POST request instead of a GET request because the both the function and MultiBaas may take additional parameters. MultiBaas can take additional parameters to support functionality such as type conversions.

Write Values: "Methods"

Write values are functions that affect the blockchain state. In the UI, write values and functions that take parameters (including "pure" functions which neither read nor write from the blockchain) are grouped together in the Methods section of the contract page.

To execute a function on the contract:

  1. Select the account you wish to use from your wallet software
  2. Select the same account from the MultiBaas Signer Selector control
  3. Click the down arrow next to the function's name to expose the parameter fields
  4. Correctly enter any required parameters
  5. Click Send Method
  6. Confirm the transaction in your wallet software

If the transaction succeeds, a success message containing the transaction hash and other details will appear below the dialogue.

To submit a function call via the API you can make a request like the following:

Request
POST .../chains/ethereum/addresses/curvetoken/contracts/mltitoken/methods/mint
{
    "args": [
        "1"
    ],
    "from": "0xBaC1Cd4051c378bF900087CCc445d7e7d02ad745",
    "signer": "0xBaC1Cd4051c378bF900087CCc445d7e7d02ad745"
}
Response
{
    "status": 200,
    "message": "success",
    "result": {
        "tx": {
            "from": "0xBaC1Cd4051c378bF900087CCc445d7e7d02ad745",
            "to": "0x1d4Ed5964A0d89B3b65a5C05241578817AA225eC",
            "value": "0",
            "gas": 37173,
            "gasPrice": "1",
            "data": "0xa0712d6800000000000000000000000000000000000000000000000000000000000003e8",
            "nonce": 29,
            "hash": "0xc7f55de8416dd56722539f464a3adfdf9f85909af4932e9c4bfa8a349a21dd8a"
        },
        "submitted": false,
        "summarizedInputs": [
            null
        ]
    }
}

MultiBaas returns the composed transaction. It will also be correctly wrapped if the from address belongs to a multi-signature wallet that is known to MultiBaas. Your application can then submit the transaction to a provider for signing and sending to the blockchain.