How To Develop and Deploy Contracts
Edit contract
You can write contracts based on any editor that supports solidity. The following will be based on Remix online editor as an example for explanation. Check here for Remix’s documentation.
For convenience of description, we use the following simple contract example:
Note: Since the SCDO mainnet is compatible with the Istanbul version of EVM, it's recommended to use the solidity version no later than 0.7.6 to develop your contracts. The features in the Berlin version of EVM is not available on the SCDO virtual machine.
The following screenshot is an illustration for Remix IDE:
Compile contract
After the contract is written and saved to a file, you can use the compile function of Remix to compile the contract and check for possible syntax errors. As shown in the screenshot, click the "Compile" button to compile the example contract. If there is an error, the compiler will point to where the possible error(s) takes place.
Deploy contract
Local test environment
After compiling the contract successfully, we can deploy the contract and test it. The best practice that we recommend is to set up a SCDO private chain node. Then, deploy the contract and call it on the private chain. If you're satisfied with the test results, you can deploy the contract to the SCDO mainnet. Our test node is set up in Ubuntu.
Get the contract's bytecode
As shown in Remix IDE, after the contract is complied successfully, click the "Deploy" icon on the left panel of Remix IDE:
Click "Deploy". If there is no error, then you will see the following:
Then click the green check icon.
You will see the following:
The value in the "input" field is the bytecode of the contract. Click the copy icon next to the bytecode string to copy it to the clipboard. Then save the copy to a safe place. The bytcode is as follows:
Deploy the contract through the client tool
Prepare a SCDO account and ensure that there is enough balance to deploy the contract. Here we use account 1S010a3fe1668c7cab5923fe0f77cb25ec21f644f1 of shard 1 and save the account keystore file.
You can download SCDO release Mac/Windows/Linux node and client tools.
Note: keystore file is generated by the following command
Start a private chain node (in our example, the node is in shard 1).
Deploy the contract using the sendtx command.
The sendtx parameter address is the node ip address; "amount" is the transaction amount (in Wen), which can usually be set to 0 for contract deployment; from is the keystore file corresponding to the sending transaction account keyfile; payload is the contract bytecode; gas is the minimum gas value required for the transaction (the default is 20000).
The return result of the above command is as follows:
You can view the contract deployment result according to the transaction Hash as the following:
Return result:
The value of the "failed" field as false in the result indicates that the contract is successfully deployed, and the value of "contract" is the contract address.
Call contract
Use Remix to get the bytecode of the method call
To use the client sendtx command to call a contract, you need to provide the payload information (bytecode) of the method of the contract to be called. This bytecode can be obtained through Remix. Below the "Deploy" button of the left side panel of Remix IDE, you can see the set and get methods. Fill in the parameter value on the right side of the set method (here it is 22) and click "set" to implement the method call.
You can see the result of the call in the log widget on the right side panel.
Click the green check icon to view the call details, where the value of "input" is the bytecode of the set method call. Here the set method call sets the variable value to 22, as shown in the above figure.
The bytecode of the set method call is:
Use sendtx to call the contract
The following command calls the set method in the above contract and sets the variable value to 22. The payload is the bytecode obtained from Remix. "From" is the account that initiated the transaction, and "to" is the contract address as shown in the return of "./client getreceipt ..." above.
Result:
By querying the receipt information, the result of the contract call can be obtained:
Return result:
Note: The account calling the contract must be in the same shard as the contract address. SCDO currently does not support cross-shard contract calls.
Use the command "call" to call contract methods
For methods that only get the value of a variable without changing the state of the contract, you can call the method through command "call". As in our example, obtaining the bytecode for "get" method, similar to the above-mentioned "set" method (the bytecode is 0x6d4ce63c here). To call the "get" method, it will look like:
The return result is:
As you can see, the variable value displayed by the result is 22 in hex format, which was previously set by the set method.
Deploy to SCDO mainnet
After the contract is fully tested as shown in the previous sections, you can deploy it to the SCDO mainnet by following the same steps as deploying it to a private net.
Last updated