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. Be careful to use a compiler that is consistent with the contract version.
For convenience of description, we use the following simple contract example:
pragma solidity ^0.4.24;
contract SimpleStorage {
uint storedData;
function set(uint x) public {
storedData = x;
}
function get() public view returns (uint) {
return storedData;
}
}
(Note: Use SCDO to deploy contracts, the recommended solidity version is 0.4.24-0.4.26)
Compile contract
After the contract is written, you can use the compile function of remix to compile the contract and check for possible syntax errors in the contract.
In the remix interface, click [Run] on the right, Environment select JavaScript VM, you can see that there is a default account, gas limit.
Below is the contract name SimpleStorage we edited. Click Deploy to test the deployment of the contract and get the bytecode.
There is a log window at the bottom of the remix middle panel, showing the result of deploying the contract. Expand the corresponding log content, you can see the status, transaction hash and other information. The input content is the bytecode corresponding to the contract.
The bytecode corresponding to the above example contract is:
Once you have the bytecode, you can use the SCDO client tool to deploy the contract.
You can find the software package under the corresponding platform in [SCDO release].
Note that deploying a contract is the same as sending a transaction. You can run the corresponding SCDO node locally or send the transaction to other SCDO nodes.
Local test environment
To ensure that the contract submitted to the SCDO mainnet is available, it is recommended to run [SCDO private chain node] locally,and deploy contract and call it based on the private chain.
Mainnet environment
After the local test environment is passed, you can deploy the contract to the SCDO mainnet by following the steps of deploying the contract on the private chain.
Deploy the contract through the client tool
Prepare an SCDO account and ensure that there is enough balance to deploy the contract. Here we use account 1S011ff44ec45b0019d4c8c2d6d63c73a563bff271 of shard 1, and save the account keystore file
The sendtx parameter 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 execution result of the above command is as follows:
The value of failed as false in the result indicates that the contract is successfully deployed, and the value of contract is the contract address
Call contract
Use sendTx to call the contract
Obtain method call bytecode through remix
To use the client sendtx command to call a contract, you need to provide the payload information of the contract call method, which can be obtained through remix. At the deployed contract at the bottom right of remix, click the small triangle on the left to see the variables and methods contained in the contract. This example contract contains set and get methods. Fill in the parameter values on the right side of set and click set to implement function call. You can see the result of the call in the log window. Click [Details] to view the call details, where the value of input is the bytecode of the method call. This example calls set and sets the variable value to 21, as shown in the following figure:
Use sendtx to call the contract
The following command calls the set method in the above contract and sets the variable value to 21. The payload is the bytecode obtained from remix, from is the account that initiated the transaction, and to is the contract address
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 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 it through call. Obtaining the payload information of the corresponding method is similar to the above-mentioned sendtx call contract method. For example, call the get method in the sample contract: