体验firefly

firefly is a very interesting project ==> https://hyperledger.github.io/firefly/

To help with the FireFly evaluation, especially how it makes digital assets management easy by supporting token standards (ERC20, ERC721, ERC1155, and other standard contracts or your custom implementations via extensions) with REST APIs and event streams, we have a minimal tutorial that you can set up locally on your laptop. Please give it a try and let us know if you have any questions.

  1. install the latest FireFly CLI:

$ go install github.com/hyperledger/firefly-cli/ff@latest

  1. initialize the FireFly stack using Ethereum as the underlying blockchain, and load the ERC20/ERC721 token connector:
1
$ ff init -t erc20_erc721
  1. start the stack named “digital-assets”
1
$ ff start digital-assets
  1. deploy the token contract. the easiest way is using Truffle. The Hyperledger implementation of the token connector has sample ERC20 and ERC721 contracts you can use to deploy to Ethereum:
1
2
3
4
5
6
7
8
9
$ git clone [git@github.com:hyperledger/firefly-tokens-erc20-erc721.git](mailto:git@github.com:hyperledger/firefly-tokens-erc20-erc721.git)

$ cd firefly-tokens-erc20-erc721

$ cd solidity

$ npm install

$ truffle migrate
  1. copy the contract address for the deployed ERC20 token contract (highlighted below in the sample output), to use in the next step
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
Starting migrations...

\> Network name: 'development'
\> Network id: 2021
\> Block gas limit: 4722986 (0x48112a)

1_initial_migration.js

Deploying 'Migrations'
\----------------------
⠋ Blocks: 0 Seconds: 0 > transaction hash: 0xb81c60fd920bf28775bd8610271c60a40380e278af97ccd18458efafe852dc99
\> Blocks: 0 Seconds: 0
\> contract address: 0x0C2c9222835692912b3999D6DAE955a9d306393d
\> block number: 6
\> block timestamp: 1648585628
\> account: 0x1eAecAb9D796Ee765865f47a78De13735619c914
\> balance: 904625697166532776746648320380374280103671755200316906558.262375061821325312
\> gas used: 272788 (0x42994)
\> gas price: 0 gwei
\> value sent: 0 ETH
\> total cost: 0 ETH


\> Saving migration to chain.
\> Saving artifacts
\-------------------------------------
\> Total cost: 0 ETH

2_deploy_contracts.js

Deploying 'ERC20WithData'
\-------------------------
⠋ Blocks: 0 Seconds: 0 > transaction hash: 0x748a60953ceacda47431210752c2a9991f77b552d19397827500feef086fc3cf
\> Blocks: 0 Seconds: 0
\> contract address: **0xB6728020f998f32afb4936f9CEcE04B1d3951895**
\> block number: 8
\> block timestamp: 1648585628
\> account: 0x1eAecAb9D796Ee765865f47a78De13735619c914
\> balance: 904625697166532776746648320380374280103671755200316906558.262375061821325312
\> gas used: 1948804 (0x1dbc84)
\> gas price: 0 gwei
\> value sent: 0 ETH
\> total cost: 0 ETH

\> Saving migration to chain.
\> Saving artifacts
\-------------------------------------
\> Total cost: 0 ETH

Summary

> Total deployments: 2
> Final cost: 0 ETH

  1. teach FireFly about the token contract so that it can start tracking transactions on the contract. For this step you can use the Swagger UI that comes with FireFly. Open http://localhost:5000/api, and expand the request entry POST /namespaces/{ns}/tokens/pools. Plugin the values as shown below (you can delete all the other optional properties in the payload):

  1. Now you can start using FireFly APIs to manage the new token contract: mint/transfer/burn.
  1. You can use the following JSON RPC command to create additional Ethereum addresses in the go-ethereum node’s built-in wallet:
1
2
3
4
5
6
$ curl -H 'Content-Type: application/json' -d '{"jsonrpc":"2.0","id":"1","method":"personal_newAccount","params":["**passw0rd**"]}' [http://localhost:5100](https://urldefense.com/v3/__http:/localhost:5100__;!!LSAcJDlP!hkQGL7MWpqV_y1r5RSaiFUgGNz3QpZ8L09BtbpQtqCn9e1jOOHhtfO9Jf5tIZlpXnXqo_Q$) | jq
{
"jsonrpc": "2.0",
"id": "1",
"result": "**0xfd5d5d96879a700c693da5092e2a6ef5ed399684**"
}
1
2
3
4
5
6
$ curl -H 'Content-Type: application/json' -d '{"jsonrpc":"2.0","id":"1","method":"personal_unlockAccount","params":["**0xfd5d5d96879a700c693da5092e2a6ef5ed399684**","**passw0rd**",0]}'  [http://localhost:5100](https://urldefense.com/v3/__http:/localhost:5100__;!!LSAcJDlP!hkQGL7MWpqV_y1r5RSaiFUgGNz3QpZ8L09BtbpQtqCn9e1jOOHhtfO9Jf5tIZlpXnXqo_Q$) |jq
{
"jsonrpc": "2.0",
"id": "1",
"result": true
}
  1. Try the minting API using the POST /namespaces/{ns}/tokens/mint endpoint:

  1. check the result of the minting transaction in the FireFly UI at http://localhost:5000/ui (for org0) and http//localhost:5001/ui (for org1):

That’s it! Now you have a local setup to explore the many features of FireFly.

  1. connect with metamask as below. by the way, the para when you add a network for firefly , please refer the info at ~/.firefly/stacks/oh/blockchain/genesis.json, here you can cat genesis block info.