token

Token CLI 允许您使用 Fabtoken client 发行、列出、转账和赎回token。

Syntax

token 命令有以下子命令:

  • issue

  • list

  • transfer

  • redeem

  • saveConfig

token issue

usage: token issue [<flags>]

Import token command

Flags:
  --help                   Show context-sensitive help (also try --help-long and
                           --help-man).
  --configFile=CONFIGFILE  Specifies the config file to load the configuration
                           from
  --peerTLSCA=PEERTLSCA    Sets the TLS CA certificate file path that verifies
                           the TLS peer's certificate
  --tlsCert=TLSCERT        (Optional) Sets the client TLS certificate file path
                           that is used when the peer enforces client
                           authentication
  --tlsKey=TLSKEY          (Optional) Sets the client TLS key file path that is
                           used when the peer enforces client authentication
  --userKey=USERKEY        Sets the user's key file path that is used to sign
                           messages sent to the peer
  --userCert=USERCERT      Sets the user's certificate file path that is used to
                           authenticate the messages sent to the peer
  --MSP=MSP                Sets the MSP ID of the user, which represents the
                           CA(s) that issued its user certificate
  --channel=CHANNEL        Overrides channel configuration
  --mspPath=MSPPATH        Overrides msp path configuration
  --mspId=MSPID            Overrides msp id configuration
  --config=CONFIG          Sets the client configuration path
  --type=TYPE              Sets the token type to issue
  --quantity=QUANTITY      Sets the quantity of tokens to issue
  --recipient=RECIPIENT    Sets the recipient of tokens to issue

token list

usage: token list [<flags>]

List tokens command

Flags:
  --help                   Show context-sensitive help (also try --help-long and
                           --help-man).
  --configFile=CONFIGFILE  Specifies the config file to load the configuration
                           from
  --peerTLSCA=PEERTLSCA    Sets the TLS CA certificate file path that verifies
                           the TLS peer's certificate
  --tlsCert=TLSCERT        (Optional) Sets the client TLS certificate file path
                           that is used when the peer enforces client
                           authentication
  --tlsKey=TLSKEY          (Optional) Sets the client TLS key file path that is
                           used when the peer enforces client authentication
  --userKey=USERKEY        Sets the user's key file path that is used to sign
                           messages sent to the peer
  --userCert=USERCERT      Sets the user's certificate file path that is used to
                           authenticate the messages sent to the peer
  --MSP=MSP                Sets the MSP ID of the user, which represents the
                           CA(s) that issued its user certificate
  --channel=CHANNEL        Overrides channel configuration
  --mspPath=MSPPATH        Overrides msp path configuration
  --mspId=MSPID            Overrides msp id configuration
  --config=CONFIG          Sets the client configuration path

token transfer

usage: token transfer [<flags>]

Transfer tokens command

Flags:
  --help                   Show context-sensitive help (also try --help-long and
                           --help-man).
  --configFile=CONFIGFILE  Specifies the config file to load the configuration
                           from
  --peerTLSCA=PEERTLSCA    Sets the TLS CA certificate file path that verifies
                           the TLS peer's certificate
  --tlsCert=TLSCERT        (Optional) Sets the client TLS certificate file path
                           that is used when the peer enforces client
                           authentication
  --tlsKey=TLSKEY          (Optional) Sets the client TLS key file path that is
                           used when the peer enforces client authentication
  --userKey=USERKEY        Sets the user's key file path that is used to sign
                           messages sent to the peer
  --userCert=USERCERT      Sets the user's certificate file path that is used to
                           authenticate the messages sent to the peer
  --MSP=MSP                Sets the MSP ID of the user, which represents the
                           CA(s) that issued its user certificate
  --channel=CHANNEL        Overrides channel configuration
  --mspPath=MSPPATH        Overrides msp path configuration
  --mspId=MSPID            Overrides msp id configuration
  --config=CONFIG          Sets the client configuration path
  --tokenIDs=TOKENIDS      Sets the token IDs to transfer
  --shares=SHARES          Sets the shares of the recipients

token redeem

usage: token redeem [<flags>]

Redeem tokens command

Flags:
  --help                   Show context-sensitive help (also try --help-long and
                           --help-man).
  --configFile=CONFIGFILE  Specifies the config file to load the configuration
                           from
  --peerTLSCA=PEERTLSCA    Sets the TLS CA certificate file path that verifies
                           the TLS peer's certificate
  --tlsCert=TLSCERT        (Optional) Sets the client TLS certificate file path
                           that is used when the peer enforces client
                           authentication
  --tlsKey=TLSKEY          (Optional) Sets the client TLS key file path that is
                           used when the peer enforces client authentication
  --userKey=USERKEY        Sets the user's key file path that is used to sign
                           messages sent to the peer
  --userCert=USERCERT      Sets the user's certificate file path that is used to
                           authenticate the messages sent to the peer
  --MSP=MSP                Sets the MSP ID of the user, which represents the
                           CA(s) that issued its user certificate
  --channel=CHANNEL        Overrides channel configuration
  --mspPath=MSPPATH        Overrides msp path configuration
  --mspId=MSPID            Overrides msp id configuration
  --config=CONFIG          Sets the client configuration path
  --tokenIDs=TOKENIDS      Sets the token IDs to redeem
  --quantity=QUANTITY      Sets the quantity of tokens to redeem

token saveConfig

usage: token saveConfig

Save the config passed by flags into the file specified by --configFile

Flags:
  --help                   Show context-sensitive help (also try --help-long and
                           --help-man).
  --configFile=CONFIGFILE  Specifies the config file to load the configuration
                           from
  --peerTLSCA=PEERTLSCA    Sets the TLS CA certificate file path that verifies
                           the TLS peer's certificate
  --tlsCert=TLSCERT        (Optional) Sets the client TLS certificate file path
                           that is used when the peer enforces client
                           authentication
  --tlsKey=TLSKEY          (Optional) Sets the client TLS key file path that is
                           used when the peer enforces client authentication
  --userKey=USERKEY        Sets the user's key file path that is used to sign
                           messages sent to the peer
  --userCert=USERCERT      Sets the user's certificate file path that is used to
                           authenticate the messages sent to the peer
  --MSP=MSP                Sets the MSP ID of the user, which represents the
                           CA(s) that issued its user certificate

Example Usage

token issue example

您可以使用以下命令来发行属于User1@org1.example.com的100个Fabcoins。Tokens由Admin@org1.example.com发行。

  • Use the --config flag to provide the path to a file that contains the connection information for your fabric network, including your Prover peer. You can find a sample configuration file below. Use the --mspPath flag to provide the path to the MSP of the token issuer.

    export CONFIG_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/configorg1.json
    export MSP_PATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
    .
    token issue --config $CONFIG_FILE --mspPath $MSP_PATH --channel mychannel --type Fabcoins --quantity 100 --recipient Org1MSP:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/User1@org1.example.com/msp
    .
    2019-03-28 18:19:29.438 UTC [token.client] BroadcastReceive -> INFO 001 calling OrdererClient.broadcastReceive
    Orderer Status [SUCCESS]
    Committed [true]
    

token list example

您可以使用 token list 命令来发现您所拥有的tokens的tokenIDs。

  • Use the --mspPath flag to provide the path to the MSP of the token owner.

    export CONFIG_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/configorg1.json
    export MSP_PATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/User1@org1.example.com/msp
    .
    token list --config $CONFIG_FILE --mspPath $MSP_PATH --channel mychannel
    

    If successful, the command will return the tokenID, which is the ID of the transaction that created the token, as well as the type and quantity of assets represented by the token.

    {"tx_id":"23604056d205c656fa757f568a6a4f0105567ebc208303065aa7e5a11849c0c8"}
    [Fabcoins,100]
    

token transfer example

您可以使用 token transfer 命令将您拥有的token转账给通道的另一个成员。

  • Use the --tokenIDs flag to select the tokens that you want to transfer. Use the --shares flag to provide a path to a JSON file that describes how the input token will be distributed to the recipients of the transaction. You can find a sample shares file below.

    export CONFIG_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/configorg1.json
    export MSP_PATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/User1@org1.example.com/msp
    export SHARES=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/shares.json
    .
    token transfer --config $CONFIG_FILE --mspPath $MSP_PATH --channel mychannel --tokenIDs '[{"tx_id":"23604056d205c656fa757f568a6a4f0105567ebc208303065aa7e5a11849c0c8"}]' --shares $SHARES
    .
    2019-03-28 18:27:43.468 UTC [token.client] BroadcastReceive -> INFO 001 calling OrdererClient.broadcastReceive
    Orderer Status [SUCCESS]
    Committed [true]
    

token redeem example

赎回的tokens不能再转账给其他通道成员。Tokens只能由其所有者赎回。您可以使用以下命令赎回50枚 Fabcoins:

```
export CONFIG_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/configorg1.json
export MSP_PATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/User1@org1.example.com/msp
.
token redeem --config $CONFIG_FILE --mspPath $MSP_PATH --channel mychannel --tokenIDs '[{"tx_id":"30e6337fdc0d07a5c46f51d6b58c4958992e21fed0aed5c822b30f9f28366698"}]' --quantity 50
.
2019-03-28 18:29:29.656 UTC [token.client] BroadcastReceive -> INFO 001 calling OrdererClient.broadcastReceive
Orderer Status [SUCCESS]
Committed [true]
```

Configuration file example

配置文件给token CLI提供您的网络的端点信息。该文件包含您的组织将用于组装token交易的校准节点。

**Sample configuration file** ``` { "ChannelID":"", "MSPInfo":{ "MSPConfigPath":"", "MSPID":"Org1MSP", "MSPType":"bccsp" }, "Orderer":{ "Address":"orderer.example.com:7050", "ConnectionTimeout":0, "TLSEnabled":true, "TLSRootCertFile":"/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem", "ServerNameOverride":"" }, "CommitterPeer":{ "Address":"peer0.org1.example.com:7051", "ConnectionTimeout":0, "TLSEnabled":true, "TLSRootCertFile":"/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt", "ServerNameOverride":"" }, "ProverPeer":{ "Address":"peer0.org1.example.com:7051", "ConnectionTimeout":0, "TLSEnabled":true, "TLSRootCertFile":"/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt", "ServerNameOverride":"" } } ```

Shares file example

转账交易使用shares文件在转账的接收者之间分配由输入token表示的资产。没有转账给接收方的任何数量的输入token都会以新token的形式自动提供给原始所有者。

**Sample shares file** ``` [ { "recipient":"Org2MSP:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/User1@org2.example.com/msp", "quantity":"50" } ] ```

Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.