如何创建和部署一个属于自己的EOS代币

发布时间:2021-12-22 15:26:05 作者:柒染
来源:亿速云 阅读:123

这篇文章将为大家详细讲解有关如何创建和部署一个属于自己的EOS代币,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。

下面我们将弄清楚什么是EOS代币以及如何自己创建和部署EOS代币。

与以太坊相反,EOS带有即插即用的代币智能合约。以太坊拥有ERC20智能合约,EOS拥有eosio.token智能合约。Eosio.token智能合约允许你通过提供最大代币供应数量和代币的书面定义,通过向帐户发放代币以及在帐户之间转移代币来创建你自己的代币。EOS区块链上的EOS代币使用相同的智能合约签发。

cleos --url https://api.main.alohaeos.com:443 get currency stats eosio.token EOS
{
  "EOS": {
    "supply": "1003605574.9616 EOS",
    "max_supply": "10000000000.0000 EOS",
    "issuer": "eosio"
  }
}

url参数指定你连接的哪一个节点。你可以在官方网站上查看更多提供API的节点。

安装Cleos

Cleos是一个命令行工具,它与nodeos公开的REST API进行交互。我们需要cleos来运行所有命令来与EOS区块链进行交互。你可以使用Docker,AWS Image或编译源代码来安装cleos。安装的最终结果必须在你的终端中是可用的。

cleos
ERROR: RequiredError: Subcommand required
Command Line Interface to EOSIO Client
Usage: cleos [OPTIONS] SUBCOMMAND

Options:
  -h,--help                   Print this help message and exit
  -u,--url TEXT=http://localhost:8888/
                              the http/https URL where nodeos is running
  --wallet-url TEXT=http://localhost:8900/
                              the http/https URL where keosd is running
  -r,--header                 pass specific HTTP header; repeat this option to pass multiple headers
  -n,--no-verify              don't verify peer certificate when using HTTPS
  -v,--verbose                output verbose actions on error
  --print-request             print HTTP request to STDERR
  --print-response            print HTTP response to STDERR
Subcommands:
  version                     Retrieve version information
  create                      Create various items, on and off the blockchain
  get                         Retrieve various items and information from the blockchain
  set                         Set or update blockchain state
  transfer                    Transfer EOS from account to account
  net                         Interact with local p2p network connections
  wallet                      Interact with local wallet
  sign                        Sign a transaction
  push                        Push arbitrary transactions to the blockchain
  multisig                    Multisig contract commands
  system                      Send eosio.system contract action to the blockchain.

创建钱包

钱包是存储可能与一个或多个帐户的权限相关联密钥的客户端。理想情况下,钱包具有受高熵密码保护的锁定(加密)和解锁(解密)状态。EOSIO/eos存储库捆绑了一个名为cleos的命令行界面客户端,它与一个名为keosd的lite客户端连接在一起,它们展示了这种模式。

让我们创建一个名为“treasure”的东西。

cleos wallet create --name treasure
Creating wallet: treasure
Save password to use in the future to unlock this wallet.
Without password imported keys will not be retrievable.
"PW5J2DTM7kpPaihUH35pLTJrvhjgZ11SY4FqxYbo6geWvEH4SNvMC"

你必须将密码保存在安全的地方,因为如果它丢失了,则无法恢复钱包内的所有密钥。

现在我们需要为所有者和活动权限生成两对密钥。之后,我们将它们导入我们的钱包。

cleos create key #owner
Private key: 5HsrZsLeUoDvBCFT2JSvgg3KrfwE7BXAJkUBSwnTwX27Cgabumj
Public key: EOS8VMwRNWWHwov4vyzJiq9uTEyzcny8QKXv7CJxGQAwjSTncyv51

cleos create key #active
Private key: 5JtrJNbJPfzm8XPMddANGYT9yzaqo8gwTEpmSrgQNhtoPXL9Ynd
Public key: EOS8CCRKHAbhBim6LimdvhhzhEYiKNnLRhuMD1Zqx5Cut52moBRmH

cleos wallet import 5HsrZsLeUoDvBCFT2JSvgg3KrfwE7BXAJkUBSwnTwX27Cgabumj --name treasure #owner
imported private key for: EOS8VMwRNWWHwov4vyzJiq9uTEyzcny8QKXv7CJxGQAwjSTncyv51

cleos wallet import 5JtrJNbJPfzm8XPMddANGYT9yzaqo8gwTEpmSrgQNhtoPXL9Ynd --name treasure #owner
imported private key for: EOS8CCRKHAbhBim6LimdvhhzhEYiKNnLRhuMD1Zqx5Cut52moBRmH

创建帐号

要在EOS区块链中执行任何操作,你需要拥有一个帐户。

帐户是存储在区块链中的我们可以看明白的名称。它可以由一个人或一些人拥有,具体取决于权限配置。需要一个帐户来将交易转移或推送到区块链。

帐户本质上是一些公共或私有密钥,是一个唯一的名称。密钥存放在钱包中。帐户存储在EOS区块链中。

在本地创建帐户很容易,你只需运行cleos create account命令,因为你拥有默认的eosio帐户,这在Mainnet上显然不是这样。要在Mainnet上创建帐户,你需要已经拥有它的人的帮助,例如zeoseos-account-creator,这需要花钱。此外,你只能创建12个符号的帐户,并且仅包含a-z小写,1-5个数字。在我看来,这是非常严格的限制。要获得名称较短的帐户,你必须进行竞价。考虑到(双关的语意)你可以转售EOS帐户,抢注量是非常巨大的。考虑到所有这些,我们将使用Testnet来节省金钱和时间。

EOS Jungle Tesnet在尽可能模拟主网。转到jungle.cryptolions.io并点击Create Account链接。它会询问你的帐户名称和两个密钥。使用之前生成的公钥。

如何创建和部署一个属于自己的EOS代币

确认后账号会被建好。

cleos --url https://jungle.eosio.cr:443 get account ylvdeveloper
permissions: 
     owner     1:    1 EOS8VMwRNWWHwov4vyzJiq9uTEyzcny8QKXv7CJxGQAwjSTncyv51
        active     1:    1 EOS8CCRKHAbhBim6LimdvhhzhEYiKNnLRhuMD1Zqx5Cut52moBRmH
memory: 
     quota:     161.4 KiB    used:     3.365 KiB  

net bandwidth: 
     staked:        100.0000 EOS           (total stake delegated from account to self)
     delegated:       0.0000 EOS           (total staked delegated to account from others)
     used:                 0 bytes
     available:        19.12 MiB  
     limit:            19.12 MiB  

cpu bandwidth:
     staked:        100.0000 EOS           (total stake delegated from account to self)
     delegated:       0.0000 EOS           (total staked delegated to account from others)
     used:                 0 us   
     available:        3.826 sec  
     limit:            3.826 sec  

producers:     <not voted>

现在我们需要为我们的帐户购买一些RAM,因为我们要发布我们的智能合约。在EOS区块链中,RAM市场上有鲸鱼玩公牛,这是另一个有钱的人投机机会。使用EOS Jungle Testnet Faucet将一些EOS代币放入你的帐户。

如何创建和部署一个属于自己的EOS代币

之后运行cleos system buyram命令购买带有EOS代币的RAM。

cleos --url https://jungle.eosio.cr:443 system buyram ylvdeveloper ylvdeveloper "10 EOS"
3481816ms thread-0   main.cpp:429                  create_action        ] result: {"binargs":"7055a5516d9576f47055a5516d9576f4a08601000000000004454f5300000000"} arg: {"code":"eosio","action":"buyram","args":{"payer":"ylvdeveloper","receiver":"ylvdeveloper","quant":"10.0000 EOS"}} 
executed transaction: 8eb30f6cfced6845e02b134946c7b6d623558f0c1a5ceff135b7e98007da692f  128 bytes  5094 us
#         eosio <= eosio::buyram                {"payer":"ylvdeveloper","receiver":"ylvdeveloper","quant":"10.0000 EOS"}
#   eosio.token <= eosio.token::transfer        {"from":"ylvdeveloper","to":"eosio.ram","quantity":"9.9500 EOS","memo":"buy ram"}
#  ylvdeveloper <= eosio.token::transfer        {"from":"ylvdeveloper","to":"eosio.ram","quantity":"9.9500 EOS","memo":"buy ram"}
#     eosio.ram <= eosio.token::transfer        {"from":"ylvdeveloper","to":"eosio.ram","quantity":"9.9500 EOS","memo":"buy ram"}
#   eosio.token <= eosio.token::transfer        {"from":"ylvdeveloper","to":"eosio.ramfee","quantity":"0.0500 EOS","memo":"ram fee"}
#  ylvdeveloper <= eosio.token::transfer        {"from":"ylvdeveloper","to":"eosio.ramfee","quantity":"0.0500 EOS","memo":"ram fee"}
#  eosio.ramfee <= eosio.token::transfer        {"from":"ylvdeveloper","to":"eosio.ramfee","quantity":"0.0500 EOS","memo":"ram fee"}
warning: transaction executed locally, but may not be confirmed by the network yet

创建合约

首先,我们必须将我们的合约上传到区块链。Cleos命令set contract通过以下位置参数执行:

* account — the account to publish a contract for.
* contract-dir — contract directory.
* wast-file — the file containing the contract WAST or WASM.
* abi-file — the ABI of the contract.

如你所见,我们需要指定wastabi文件。如果你通过源代码构建EOS,可以在./build/contracts/eosio.token/文件夹中找到它们。为方便起见,我上传了他们两个 wast/abi。 我们用自己的帐户和文件调用set contract命令。因为我们的wast/abi文件与目录名称是相同,所以我们可以跳过这些参数。

cleos --url https://jungle.eosio.cr:443 set contract ylvdeveloper ./contracts/eosio.token
Reading WAST/WASM from ./contracts/eosio.token/eosio.token.wasm...
Using already assembled WASM...
Publishing contract...
executed transaction: 3fa704e4c1c72050e61882460bf0acd3b200df087d86a157d3d60ec1c439ba65  8104 bytes  3178 us
#         eosio <= eosio::setcode               {"account":"ylvdeveloper","vmtype":0,"vmversion":0,"code":"0061736d01000000017e1560037f7e7f0060057f7...
#         eosio <= eosio::setabi                {"account":"ylvdeveloper","abi":"0e656f73696f3a3a6162692f312e30010c6163636f756e745f6e616d65046e616d6...
warning: transaction executed locally, but may not be confirmed by the network yet

让我们检查代码是否已使用get code ylvdeveloper命令上传。

cleos --url https://jungle.eosio.cr:443 get code ylvdeveloper
code hash: 641f336aa1d08526201599c3c0ddb7a646e5ac8f9fd2493f56414d0422a0f957

创建代币

最后,我们可以创建和发布我们的令牌。我们将使用cleos push action命令利用我们的智能合约的创建和发布,该命令采用以下参数:

* contract — the account providing the contract to execute.
* action — the action to execute on the contract.
* data — the arguments to the contract.

让我们创建YLV代币并发出一些代币。

cleos --url https://jungle.eosio.cr:443 push action ylvdeveloper transfer '{"from":"ylvdeveloper", "to":"ylvio", "quantity":"100.00 YLV", "memo":"gift"}' -p ylvdeveloper
executed transaction: 32abee7e426d9e5653f67a7b492c17ca62aeeef97ff1a86037f58f2dd1459452  136 bytes  1639 us
#  ylvdeveloper <= ylvdeveloper::transfer       {"from":"ylvdeveloper","to":"ylvio","quantity":"100.00 YLV","memo":"gift"}
#         ylvio <= ylvdeveloper::transfer       {"from":"ylvdeveloper","to":"ylvio","quantity":"100.00 YLV","memo":"gift"}

检查下余额:

cleos --url https://jungle.eosio.cr:443 get table ylvdeveloper ylvdeveloper accounts
{
  "rows": [{
      "balance": "900.00 YLV"
    }
  ],
  "more": false
}
Bytezilla:build iYalovoy$ cleos --url https://jungle.eosio.cr:443 get table ylvdeveloper ylvio accounts
{
  "rows": [{
      "balance": "100.00 YLV"
    }
  ],
  "more": false
}

按预期完成了我们的工作,很完美。

我们从安装cleos和了解eosio.token智能合约再到拥有我们自己的代币并将代币转移到其他帐户的全部过程。我们使用EOS Jungle Testnet完成了所有这一切,它几乎与Mainnet相同。相同的步骤适用于Mainnet,你只需使用不同的API节点并为你的帐户和RAM支付相应的费用。

关于如何创建和部署一个属于自己的EOS代币就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

推荐阅读:
  1. Docker构建和Web应用部署
  2. RMS 权限策略模板创建和部署

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

eos

上一篇:如何在IPFS里面上传一张图片

下一篇:mysql中出现1053错误怎么办

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》