Link a deployed smart-contract

Besides deploying a smart contract to a new address, you can also link a smart contract to an existing instance.

The effect of linking a smart contract to an address in MultiBaas tells MultiBaas that the bytecode on the blockchain at that address can be interacted with via the methods in that smart contract.

One feature of MultiBaas is that multiple smart contracts (really, their ABIs) can be linked to a single blockchain address. This allows a layering of functionality, where a smart contract developer can choose which contract’s ABI to access a deployed contract instance with.

Similar to C header (.h) files, a contract that contains the methods within that header file can be interacted with, even if it contains additional functionality not specified in a given header file (i.e., in a given ABI).

For example, the ERC20 token standard defines a series of Solidity methods that a smart contract must implement, but does not limit the smart contract from implementing additional functionality.

Linking via the UI

After uploading a solidity file containing one or more smart contracts, you will be prompted to deploy or link the compiled contracts to a blockchain network.

You can also reach the link function using the following steps:

  1. Select Contracts from the main menu
  2. Select a specific contract from the Contracts side menu
  3. Click on Deploy / Link Contract at the top of the contract window

From the Deploy / Link dialogue you can then:

  1. Select the Link tab.
  2. Select the version of the contract you wish to link
    • The version numbers are those chosen when uploading the contract
    • By default, the selected version will be the most recent version according to lexicographical ordering, not the most recently uploaded version
  3. Choose a label for the linked contract
    • This will be an instance label corresponding to the deployed at address
  4. Enter the actual contract address (not a label or alias)
  5. Click Link on network where network is the network to which MultiBaas is connected

If successful, you will see a message indicating the linked address and label. The link dialogue will remain open in case you want to link more instances of the same contract. The linked contract instance will be available under the Contracts menu under the type of contract that was linked.

Linking via the API

Linking a deployed smart contract to an address can be performed with the following REST API call.

Request:

Copy
Copied
PUT /chains/ethereum/addresses/mltitoken/contracts/mltitoken

Response:

Copy
Copied
{
    "status": 200,
    "message": "Success",
    "result": {
        "label": "mltitoken",
        "address": "0xB98e9bFF193adB14f75821D638F8Fc34F07E6c1C",
        "balance": 0,
        "chain": "ethereum",
        "isContract": true,
        "modules": [],
        "contracts": [
            {
                "name": "",
                "label": "mltitoken",
                "conflict": false,
                "version": "1.0"
            }
        ]
    }
}

The response shows that the mltitoken address is linked to the mltitoken contract, and hence its ABI for interacting with it.

Copyright © Curvegrid 2022. All right reserved.