2个版本
0.1.1 | 2023年1月31日 |
---|---|
0.1.0 | 2023年1月20日 |
#6 in #balance
210KB
5.5K SLoC
HMIP20
hmip20智能合约,用于Hermit网络。
下载
git clone https://github.com/HermitMatrixNetwork/hmip20.git
编译前
apt update && apt install -y binaryen clang
编译
cd himp20
cargo test
make compile-optimized
此命令将输出一个文件 contract.wasm.gz
。
HMIP20合约使用方法
存储合约代码
ghmd tx compute store contract.wasm.gz --from a --gas 1000000 --gas-prices 0.25ughm
使用 ghmd q compute list-code
,找到上传合约的数量
实例化代币合约
ghmd tx compute instantiate <code-id> \
'{"name":"<your_token_name>","symbol":"<your_token_symbol>","admin":"<optional_admin_address_defaults_to_the_from_address>","decimals":<number_of_decimals>,"initial_balances":[{"address":"<address1>","amount":"<amount_for_address1>"}],"prng_seed":"<base64_encoded_string>","config":{"public_total_supply":<true_or_false>,"enable_deposit":<true_or_false>,"enable_redeem":<true_or_false>,"enable_mint":<true_or_false>,"enable_burn":<true_or_false>}}' \
--label <token_label> \
--from <account>
配置您的合约
"config":{
"public_total_supply":<true_or_false>,
"enable_deposit":<true_or_false>,
"enable_redeem":<true_or_false>,
"enable_mint":<true_or_false>,
"enable_burn":<true_or_false>
}
执行代币合约
存款
ghmd tx compute execute <contract_address> '{"deposit":{}}' --amount 1000000ughm --from <account>
赎回
ghmd tx compute execute <contract-address> '{"redeem": {"amount": "<amount_in_smallest_denom_of_token>"}}' --from <account>
转账
'{"transfer":{"amount":"<string>","recipient":"<address_string>"}}'
发送
'{"send":{"amount": <string>, "recipient": <string>}}'
批量转账
'{"batch_transfer":{"actions":[{"amount": <string>, "recipient": <string>}]}}'
批量发送
'{"batch_send":{"actions":[{"amount":<string>, "recipient":<string>}]}}'
销毁
'{"burn":{"amount": <string>}}'
注册接收
'{"register_receive": {"code_hash": <string>}}'
创建查看密钥
'{"create_viewing_key":{"entropy": <string>}'
设置查看密钥
ghmd tx compute execute <contract-address> '{"set_viewing_key": {"key": "<your_key>"}}' --from <account>
增加允许额度
'{"increase_allowance":{"spender": <string>, "amount": <striong>}'
减少允许额度
'{"decrease_allowance":{"spender": <string>,"amount":<string>}}'
从转账
'{"transfer_from":{"amount":<string>, "owner":<string>, "recipient":<string>}}'
从发送
'{"send_from":{"amount":<string>, "owner":<string>, "recipient":<string>}'
批量从转账
'{"batch_transfer_from":{"actions":[{"amount":<string>, "owner":<string>, "recipient":<string>}]}'
批量从发送
'{"batch_send_from":{"actions":[{"amount":<string>, "owner":<string>, "recipient":<string>}]}'
从销毁
'{"burn_from":{"amount":"<string>"", "owner":"<string>"}'
批量从销毁
'{"batch_burn_from":{"actions":[{"amount":"<string>"", "owner":"<string>"}]}'
铸造
'{"mint":{"amount":"<string>","recipient":"<string>"}}'
批量铸造
'{"batch_mint":{"actions":[{"amount":"<string>","recipient":"<string>"}]}}'
更改管理员
'{"change_admin":{"address":"<str>"}}'
设置合约状态
'{"set_contract_status":{"level":"<string>"}}'
// normal_run
// stop_all_but_redeems
// stop_all
添加铸造者
'{"add_minters":{"minters":["str1","str2"]}}'
移除铸造者
'{"remove_minters":{"minters":["str1","str2"]}}'
设置铸造者
'{"set_minters":{"minters":["str1","str2"]}}'
撤销许可
'{"revoke_permit":{"permit_name":"<string>"}}'
查询代币合约信息
TokenInfo
'{"token_info":{}}'
TokenConfig
ghmd q compute query <contract-address> '{"token_config": {}}'
ContractStatus
'{"contract_status":{}}'
ExchangeRate
ghmd q compute query <contract-address> '{"exchange_rate": {}}'
Minters
'{"minters":{}}'
WithPermit
// todo
'{"with_permit":{"permit":{},"query":""}}'
Balance
'{"balance":{"address":"<str>","key":"str"}}'
TransferHistory
'{"transfer_history":{"address":"<str>","key":"<str>","page_size":<int>}}'
TransactionHistory
'{"transaction_history":{"address":"<str>","key":"<str>","page_size":<int>}'
Allowance
'{"allowance":{"key":"<string>","owner":"<string>","spender":"<string>"}}'
依赖
~3–4.5MB
~98K SLoC