Deploy a Smart Contract
In this chapter we will deploy an HRC20 token smart contract on Htmlcoin. All HRC20 compliant token contracts support a common set of methods:
Because all tokens share the same interface, it is much easier for wallets and exchanges to support all the different tokens out there in the wild.
StandardToken implements the ERC20 interface.
MintableToken adds the mint(address _to, uint256 _amount) method, to create new tokens out of thin air.
CappedToken adds limit to the max supply of tokens that could be minted.
Create the project directory, and clone the zeppelin-solidity repository to the project directory:
The Owner Address
The HRC20 token we deploy will be "owned" by a particular UTXO address. A few administrative methods are protected, such that only the owner of the contract may use them.
These methods are protected by the onlyOwner modifier, which checks whether the msg.sender is the contract's owner:
For example, the method mint makes sure that only the owner can use it:
Create The Owner Address And Fund It
Let's generate an address to act as the owner.
There's nothing special about this address. You could use the address of any UTXO in your wallet.
Let's fund the owner address with 10 HTML, to pay for gas when we deploy our contract later:
After the payment confirms, you should that there is one UTXO for this owner address:
Finally, we'll need to configure the deployment tool solar to use this particular address as the owner:
It takes quite a few steps to deploy a contract:
Use the solidity compiler to compile the contract into bytecode.
ABI encode the _capacity parameter into bytes.
Concatenate 1 and 2 together, then make a createcontract RPC call to htmlcoind.
Wait for transaction to confirm.
Record the address of the contract, and owner of the contract, for later uses.
The solar Smart Contract deployment tool (included in the container) handles all of this for you.
Install Solidity and Solar
To deploy the CappedToken contract, specifying 21 million as the capacity by passing in the constructor parameters as a JSON array (remember to set HTMLCOIN_SENDER):
Then solar waits for confirmation:
The contract had been deployed to a778c05f1d0f70f1133f4bbf78c1a9a7bf84aed3. (You'd get a different contract address).
The solar status command lists all contracts that had been deployed with solar:
Note that the contract's owner should be set to the HTMLCOIN_SENDER value we have specified earlier. If you did not set QTUM_SENDER to anything, a random UTXO from the wallet is selected, and that become the owner.
You can find more information about the deployed contracts in solar.development.json.