Add a smart-contract
Upload a smart contract source-code
MultiBaas currently supports Ethereum smart contracts written in the Solidity programming language, although support for additional blockchain types and smart contract programming languages may be added in the future.
A Solidity smart contract consists of one or more files which are compiled from textual source code into Ethereum Virtual Machine (EVM) bytecode and application binary interface (ABI). The ABI is metadata which describes the functions (methods) and events of the smart contract, including the input and output parameter types of each. The canonical Solidity compiler is solc.
Prepare a smart-contract for upload
Due to the compilation process, it is currently required to combine your contracts into a single file before uploading. For example, suppose you have the following two dependent contracts:
ERC20.sol
pragma solidity ^0.5.16;
contract ERC20 is Ownable {
//Contract contents...
}
Ownable.sol
pragma solidity ^0.5.16;
contract Ownable {
//Contract contents...
}
The two contracts must be combined together in one syntactically correct solidity file:
MyToken.sol
pragma solidity ^0.5.16;
contract ERC20 is Ownable {
//Contract contents...
}
contract Ownable {
//Contract contents...
}
They will be compiled using solc 0.5.16. During the contract upload process you will be able to select which of the contracts contained in the file should be saved in MultiBaas.
Uploading a smart contract
To upload a smart contract:
- Select Contracts from the main menu
- Click New Contract from the side menu
- Ensure you are on the Solidity tab at the top of the the Upload Smart Contracts window
- Click Select Files from the Upload Smart Contracts window
- Open the prepared solidity file from the file selection dialogue
MultiBaas compiles the smart contract client-side and provides feedback as to what sub-contracts are present in the source code.
MultiBaas suggests labels and versions for each of the sub-contracts in the file. The suggested label is based on the name of the contract and the version is based on the number of times a contract of that name has been uploaded.
- Select the sub-contracts to import into MultiBaas
- Review or update the label and version of each of the selected sub-contracts you wish to upload
- Click Submit to upload the selected contracts
Note that at this time the smart contract source code, bytecode, ABI and other metadata have been persisted to the MultiBaas database. The ABI is the primary source of information about the smart contract, and is generated by the Solidity compiler, solc.
After submitting a contract you will be prompted to a deploy it to the network or link it to an existing address.
Upload a smart contract with Truffle/Hardhat JSON
MultiBaas currently supports adding a smart contract by uploading the build artifact output generated by Truffle or Hardhat when a contract is compiled. The build artifact is a .json
file containing the contract ABI, and other information required to deploy and interact with your contract.
MultiBaas also offers plugins for both Truffle and Hardhat to help you integrate your MultiBaas into your workflow. You can check them out at truffle-multibaas-plugin and hardhat-multibaas-plugin
Generating the build artifact
Truffle/Hardhat will generate the build artifact when you compile your contract code. For more information on compiling your artifact using each tool, read the official Truffle docs or Hardhat docs.
Upload the artifact file
First, navigate to the upload window:
- Select Contracts from the main menu
- Click New Contract from the side menu
- Select the JSON tab at the top of the Upload Smart Contracts window
Create fill in your contract details:
- Provide a Label and Version for your new contract
- Select the Truffle/Hardhat Compiled Artifact option beside the Select File button
- Click Select File and upload your prepared artifact
MultiBaas will parse the JSON file into the following properties:
bin* string
rawABI* string
contractName string
userDoc string
developerDoc string
metadata string
which will be auto-populated into the Contract Textbox.
- Review these properties and make any necessary changes directly in the textbox before submitting
- Click Submit to add the contract. You must have a Label and Version for your new contract to submit.
Note, you may also upload the contract by pasting the contents of the JSON file directly into the Contract Textbox. However, the pasted JSON must have the property names described above, which may require you to manually rename the fields. To confirm the property names, you may the click the Show Schema toggle in the textbox header. The asterisk after the property name is to denote that it is mandatory.
The JSON present in the contract textbox is the data that will ultimately be uploaded to MultiBaas, so any change that you make in the textbox will override the file data that was initially uploaded through the Upload/Parse JSON File window.