Details on how Starcoin upgrades Stdlib with on-chain governance

Smart Contracts: Starcoin vs ETH

1.Languages used by smart contracts

Ethernet: Most of the contracts in Ethernet are written in solidity, and the tokens of protocols such as ERC20 need to be implemented by themselves during the writing process, and there is no stdllib standard library.

Starcoin: Starcoin’s contracts are written in the move language, which has the concept of module and script. module is mostly used to write basic code, and script is used to combine calls. There is stdlib in Starcoin, which has built-in implementation of ERC20, NFT, Dao and other protocols, and the move language supports paradigms, so it is easy to create different Tokens and other functions.

2. Smart contract invocation and storage

Ethernet: Ethernet is divided into contract address and non-contract address, the contract needs to be placed in the contract address, so when calling the contract, you need to find the contract through the contract address. If the contract is upgraded, you need to change the contract address to use the new contract when you don’t use methods like Proxy contract (proxy contract).

Starcoin: Starcoin’s contracts and other resources (NFT …) Starcoin contracts and other resources (NFT …) are stored in the account address, so when calling a contract you need to find the contract by using the owner address + module. If a contract is upgraded, it will not affect the address and module name of the calling contract.

Smart Contract Upgrade: Starcoin vs ETH

Ethernet: If a contract on Ethernet needs to be upgraded but you don’t want to change the address of the calling contract, you can use a Proxy contract to access the address of the proxy contract, which will provide the address of the new contract.

Starcoin: Starcoin’s contracts need to be upgraded by Dao community voting, Two-phase (two-phase submission) to solve the problem, after the upgrade can use the original address to call the new contract.

Contract upgrade solution: Starcoin vs ETH

Starcoin’s stdlib contract exists on the chain and is managed using Dao on-chain governance. The community can decide on the deployment of the contract upgrade plan through a voting operation.

Code submission is a two-stage submission: the upgrade plan is submitted first, and then the updated code is submitted. The whole process is divided into seven stages, as shown in the figure.

●Upgrade complete


After the coder has modified the code and submitted an upgrade proposal txn to Dao, the process enters the PENDING state. Set a period of time for the community to discuss and understand the topic before moving on to the next stage.


At the end of the previous phase, we enter the ACTIVE phase, in which we need the community to vote, and then move to the next phase after the set time.


After the previous phase reaches the specified time, the process enters the AGREED phase, in which the voting results are counted, and if the percentage exceeds the predetermined percentage, the upgrade plan is considered to be allowed by the Dao community, and after the public announcement is launched, the next phase can be carried out.


After the voting results are counted in the previous phase, the process enters the public period from the launch of the public announcement to the public announcement period, this phase is mainly to display the information of the sponsor and proposal, etc., when the public announcement period is over, the next phase is entered.


After the public period of the previous phase is over, the process enters the first phase of the Two-phase (two-phase submission) in which the contract can be upgraded, and the contract code upgrade plan is submitted. After submitting the contract upgrade plan, you can move on to the next phase.


After submitting the contract upgrade plan in the previous phase, the process moves to the second phase of the two-phase upgrade contract (two-phase submission), where you can submit the code to fix or upgrade the contract.

7. Upgrade complete

After the code of the previous phase is submitted, the whole contract upgrade process is finished, after which you can use the new contract code to operate.

Stdlib upgrade practice

1.Write the code in stdlib

Here, take DummyToken.move in stdlib as an example, add a Mymint function and Mymint script. The function is to create 100 DummyTokens with a fixed value.

The DummyToken Module under DummyToken.move:

/// Anyone can mint DummyToken, amount should < 10000
public fun mint(_account: &signer, amount: u128) : Token<DummyToken> acquires SharedMintCapability{
assert(amount <= 10000, Errors::invalid_argument(EMINT_TOO_MUCH));
let cap = borrow_global<SharedMintCapability>(token_address());
Token::mint_with_capability(&cap.cap, amount)

// Add new function here
public fun Mymint(_account: &signer) : Token<DummyToken> acquires SharedMintCapability{
let cap = borrow_global<SharedMintCapability>(token_address());
Token::mint_with_capability(&cap.cap, 100)

/// Return the token address.
public fun token_address(): address {

DummyTokenScripts Module under DummyToken.move:

public(script) fun mint(sender: signer, amount: u128){
let token = DummyToken::mint(&sender, amount);
let sender_addr = Signer::address_of(&sender);
Account::deposit(sender_addr, token);

//Add the new script function here
public(script) fun Mymint(sender:signer){
let token = DummyToken::Mymint(&sender);
let sender_addr = Signer::address_of(&sender);
Account::deposit(sender_addr, token);

2. Prepare the compiled binary Module

Execute the command from the Starcoin command line to compile and package the compiled binary Module in two steps.

dev compile -s 0x1 path/to/DummyToken.move

"ok": [

To package:

dev package -n MymintUpgrade -o storage path/to/DummyToken*

"ok": {
"file": "path/to/storage/MymintUpgrade.blob",
"package_hash": "0x6e54935144115233c9decb255d3bcd5f14c7b9d82c968c5f3a0cb1b14f18bce8"

3. Prepare the account number and balance

Prepare the account number: two accounts are needed.

1.coder account: used to submit plans and submit code, etc.

2.polling delegate account: used to vote

Use the key to import or use account create to create the account.

Prepare the balance:

1. coder account needs a certain amount of STC as GAS fee for proposal and upgrade, etc.

2. the voting delegate account needs a large amount of STC for voting.

Use the command line account unlock account address to unlock the account

To obtain the STC method:

Default account acquisition
dev get-coin -v 6000000STC
Transfer method
account transfer -s 0x0000000000000000000000000a550c18 -r <Account Receipt Identifier> -v 60000000000000000 -b

4. submit proposal Enter PENDING

Submit a Proposal
dev module-proposal -s <account address> -m <module path> -v <version> -e false

●m indicates the path of the upgrade package.
●v indicates the new version number.
●e indicates whether to skip the module compatibility check to force the upgrade, false indicates not to skip the compatibility check, and the default is not to skip it.

5. Query the status of the proposal

Check the proposal id:

dev call --function 0x1::Dao::proposal_info -t 0x1::STC::STC -t 0x1::UpgradeModuleDaoProposal::UpgradeModuleV2 --arg <proposal address>

Check the status of the proposal:

dev call --function 0x1::Dao::proposal_state -t 0x1::STC::STC -t 0x1::UpgradeModuleDaoProposal::UpgradeModuleV2 --arg <proposal address> --arg <proposal_id>
"ok": [

6. wait for community debate Enter ACTIVE

After a period of time in the PENDING state to enter the voting period, you can speed up the blockchain time to the next stage by sleep under dev,Accelerate into

Acceleration time
dev sleep -t 3600000
Generate blocks (effective time)
dev gen-block

Check proposal status:

dev call --function 0x1::Dao::proposal_state -t 0x1::STC::STC -t 0x1::UpgradeModuleDaoProposal::UpgradeModuleV2 --arg <proposal address> --arg <proposal_id>
"ok": [
Change to ACTIVE state

7. Community Voting Enter AGREED

After participating in the voting with the voting representative account and waiting for the voting time to end, the process enters AGREED stage

account execute-function -s <account address> --function 0x1::DaoVoteScripts::cast_vote -t 0x1::STC::STC -t 0x1::UpgradeModuleDaoProposal::UpgradeModuleV2 --arg <proposal address> --arg <proposal_id> --arg true --arg 59000000000000000u128

8. AGREED proposals are placed in the update queue into QUEUED

After entering AGREED, anyone can put a proposal with the status AGREED into the update queue.

dev module-queue -s <account address> -a <proposal address> -i <proposal_id>

9. public-period wait Enter EXECTABLE

After the public period wait time has passed, you can enter the execution phase. dev can accelerate this phase with the command Accelerated entry

Acceleration time
dev sleep -t 3600000
Generate blocks (effective time)
dev gen-block

10. submit the upgrade plan Enter ETRACTED

This step is the executable phase and allows you to execute the upgrade plan.

dev module-plan -i <proposal_id> -a <proposal address>  -s <account address>

11. Commit the code to Upgrade complete

In this step the Dao process is finished and the two-stage commit process enters the final stage Code module commit

dev module_exe -m path/to/storage/MymintUpgrade.blob -s <account address>

12. Complete the contract upgrade process

At this point, the entire contract upgrade process has been completed

13. Verification of upgrade

You can execute the Mymint function in the DummyTokenScripts module to verify if the upgrade is successful

Execute to get DummyToken 100
account execute-function --function 0x1::DummyTokenScripts::Mymint -b -s <account address>
account show <account address>
"balances": {
"0x00000000000000000000000000000001::DummyToken::DummyToken": 100,
"0x00000000000000000000000000000001::STC::STC": 9999645054



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store


Starcoin is a proof-of-work blockchain that enables secure smart contracts based on Move to power services in Web 3.0