Halffin is a peer-to-peer real-world assets marketplace where strangers can trade without middlemen using chainlink oracle to track delivery status ensuring buyers will be charged only if the product is received. This project is part of Chainlink Hackathon Fall 2021.
Please install or have installed the following:
- Set up repo
git clone https://github.com/palsp/halffin-adapter.git
git clone https://github.com/palsp/halffin-frontend.git- Install Brownie, if you haven't already. Here is a simple way to install brownie.
python3 -m pip install --user pipx
python3 -m pipx ensurepath
# restart your terminal
pipx install eth-brownieOr, if that doesn't work, via pip
pip install eth-brownie-
Set up external adapters
- install dependencies
npm --prefix halffin-adapter install
or
yarn --cwd halffin-adapter install- start server
yarn emulator:startNOTE: We use AWS DynamoDB in this step, please set up aws cli and sufficient iam permission to create DynamoDB Table
- Setup env
Set your WEB3_INFURA_PROJECT_ID, PRIVATE_KEY, and CHAINLINK_NODE_ADDRESS environment variable
- You can get a
WEB3_INFURA_PROJECT_IDby getting a free trial of Infura - You can find your
PRIVATE_KEYfrom your ethereum wallet like metamask. - You can get a
CHAINLINK_NODE_ADDRESSfrom gui of chainlik node.- Go to Keys > Account Address > Address
- deploy oracle
brownie run scripts/oracle_node/deploy_oracle --network kovan- Setup bridge and create job
You can use
localhost:3000for local development
- Create a job in chainlink node gui using the following job's description. Replace
ORACLE_ADDRESSwith the oracle's address deployed in the previous step andBRIDGE_NAMEwith the bridge name.
type = "directrequest"
schemaVersion = 1
name = "get-tracking-detail"
contractAddress = <ORACLE_ADDRESS>
maxTaskDuration = "0s"
observationSource = """
decode_log [type="ethabidecodelog"
abi="OracleRequest(bytes32 indexed specId, address requester, bytes32 requestId, uint256 payment, address callbackAddr, bytes4 callbackFunctionId, uint256 cancelExpiration, uint256 dataVersion, bytes data)"
data="$(jobRun.logData)"
topics="$(jobRun.logTopics)"]
decode_cbor [type="cborparse" data="$(decode_log.data)"]
fetch [type=bridge name=<BRIDGE_NAME> requestData="{\\"id\\" : $(jobSpec.externalJobID), \\"data\\" : { \\"trackingId\\" : $(decode_cbor.trackingId)}}"]
parse [type="jsonparse" path="data,tracking,tag" data="$(fetch)"]
encode_data [type="ethabiencode" abi="(bytes32 value)" data="{ \\"value\\": $(parse) }"]
encode_tx [type="ethabiencode"
abi="fulfillOracleRequest(bytes32 requestId, uint256 payment, address callbackAddress, bytes4 callbackFunctionId, uint256 expiration, bytes32 data)"
data="{\\"requestId\\": $(decode_log.requestId), \\"payment\\": $(decode_log.payment), \\"callbackAddress\\": $(decode_log.callbackAddr), \\"callbackFunctionId\\": $(decode_log.callbackFunctionId), \\"expiration\\": $(decode_log.cancelExpiration), \\"data\\": $(encode_data)}"
]
submit_tx [type="ethtx" to=<ORACLE_ADDRESS> data="$(encode_tx)"]
decode_log -> decode_cbor -> fetch -> parse -> encode_data -> encode_tx -> submit_tx
"""- Once created you will received external Job ID. Paste the job id in
brownie-config.yamlpost_job_id field.
- contract deployment
NOTE: We will keep our adapter and chainlink node up and running on kovan network until the end of December 2021. if you are running on kovan and wish to use our oracle, feel free to skip to instruction 3.
brownie run scripts/escrow-factory/deploy_factory.py --network kovan- Setup frontend
yarn --cwd halffin-frontend installSet your REACT_APP_MORALIS_SERVER_URL, REACT_APP_MORALIS_APP_ID, REACT_APP_TRACKING_SERVER_URL, and REACT_APP_NFTSTORAGE_TOKEN environment variable
- You can get
REACT_APP_MORALIS_SERVER_URLandREACT_APP_MORALIS_APP_IDfrom your moralis dashboard. REACT_APP_TRACKING_SERVER_URLis the external adapter from step 3- You can get
REACT_APP_NFTSTORAGE_TOKENfrom nft.storage
- Deploy Moralis cloud function
moralis-admin-cli watch-cloud-folder --moralisApiKey <MORALIS_API_KEY>
--moralisApiSecret <MORALIS_API_SECRET> --moralisSubdomain <MORALIS_SUB_DOMAIN> --autoSave 1 --moralisCloudfolder halffin-frontend/cloud_function- Start frontend
yarn --cwd halffin-frontend startWe provide a mock tracking number so that you do not need to ship anything in order to use our platform. Here the list of tracking number as well as its related delivery status
- Delivered
HF123456789DL
- Fail
HF123456789EX
- In Transit
HF123456789IT
This project is licensed under the MIT license.
