Ensure you use gofmt
so that golang
files match expected language standards. The plugin for Sublime is here https://packagecontrol.io/packages/Gofmtâ
If you get errors compiling because it can't find modules, some may be private currently. This explains how to solve it https://stackoverflow.com/a/44247040â
This repository uses golang
modules. Learn more here https://cosmos.network/docs/tutorial/gomod.html and here https://github.com/golang/go/wiki/Modulesâ
If you want to build the dawn
application in this repo to see the functionalities, Go 1.12.1+
is required .
Add some parameters to environment is necessary if you have never used the go mod
before.
mkdir -p $HOME/go/binecho "export GOPATH=$HOME/go" >> ~/.bash_profileecho "export GOBIN=\$GOPATH/bin" >> ~/.bash_profileecho "export PATH=\$PATH:\$GOBIN" >> ~/.bash_profileecho "export GO111MODULE=on" >> ~/.bash_profilesource ~/.bash_profile
These modules can be added to any Cosmos-SDK based chain, but a demo application/blockchain is provided with example code for how to integrate them. It can be installed and built as follows:
# Clone the repositorymkdir -p $GOPATH/src/github.com/cosmoscd $GOPATH/src/github.com/cosmosgit clone https://github.com/BlockKungPao/fbchaincd fbchain && git checkout masterâ# Install dep, as well as your dependenciesmake get_toolsdep ensure -vgo get -u github.com/kardianos/govendorâ# Fetch the C file dependencies (this is a manual hack, as dep does not support pulling non-golang files used in dependencies)govendor fetch -tree github.com/ethereum/go-ethereum/crypto/secp256k1â# Install the app into your $GOBINmake installâ# Now you should be able to run the following commands, confirming the build is successful:fbd helpfbcli helpfbrelayer help
First, initialise a chain and create accounts to test sending of a random token.
# Initialize the genesis.json file that will help you to bootstrap the networkfbd init --chain-id=testingâ# Create a key to hold your validator account and for another test accountfbcli keys add validator# Enter passwordâfbcli keys add testuser# Enter passwordâfbd add-genesis-account $(fbcli keys show validator -a) 1000000000stake,1000000000atomâ# Now its safe to start `fbd`fbd startâ# Then, wait 10 seconds and in another terminal window, test things are ok by sending 10 tok tokens from the validator to the testuserfbcli tx send $(fbcli keys show testuser -a) 10stake --from=validator --chain-id=testing --yesâ# Confirm token balances have changed appropriatelyfbcli query account $(fbcli keys show validator -a) --trust-nodefbcli query account $(fbcli keys show testuser -a) --trust-nodeâ# Next, setup the staking module prerequisites# First, create a validator and stakefbcli tx staking create-validator \--amount=100000000stake \--pubkey=$(fbd tendermint show-validator) \--moniker="test_moniker" \--chain-id=testing \--commission-rate="0.10" \--commission-max-rate="0.20" \--commission-max-change-rate="0.01" \--min-self-delegation="1" \--gas=200000 \--gas-prices="0.001stake" \--from=validatorâ# Then wait 10 seconds then confirm your validator was created correctly, and has become Bonded statusfbcli query staking validators --trust-nodeâ# See the help for the ethbridge create claim functionfbcli tx ethbridge create-claim --helpâ# Now you can test out the ethbridge module by submitting a claim for an ethereum prophecy# Create a bridge claim (Ethereum prophecies are stored on the blockchain with an identifier created by concatenating the nonce and sender address)fbcli tx ethbridge create-claim 0 0x7B95B6EC7fbd73572298cEf32Bb54FA408207359 $(fbcli keys show testuser -a) $(fbcli keys show validator -a --bech val) 3eth --from validator --chain-id testing --yesâ# Then read the prophecy to confirm it was created with the claim addedfbcli query ethbridge prophecy 0 0x7B95B6EC7fbd73572298cEf32Bb54FA408207359 --trust-nodeâ# And finally, confirm that the prophecy was successfully processed and that new eth was minted to the testuser addressfbcli query account $(fbcli keys show testuser -a) --trust-node
First, run the cli rest-server
fbcli rest-server --trust-node
An api collection for Postman (https://www.getpostman.com/) is provided here which documents some API endpoints and can be used to interact with it. Note: For checking account details/balance, you will need to change the cosmos addresses in the URLs, params and body to match the addresses you generated that you want to check.
For automated relaying, there is a relayer
service that can be run that will automatically watch and relay events.
# Check fbrelayer connection to fbdfbrelayer statusâ# Initialize the Relayer service for automatic claim processingfbrelayer init testing wss://ropsten.infura.io/ws ec6df30846baab06fce9b1721608853193913c19 "LogLock\(bytes32,address,bytes,address,uint256,uint256\)" validatorâ# Enter password and press enter# You should see a message like: Started ethereum websocket... and Subscribed to contract events...
The relayer
will now watch the contract on Ropsten
and create a claim whenever it detects a lock event.
With the application set up and the relayer
running, you can now use Peggy by sending a lock
transaction to the smart contract. You can do this from any Ethereum wallet/client that supports smart contract transactions.
The easiest way to do this for now, assuming you have Metamask setup for Ropsten in the browser is to use remix
or mycrypto
as the frontend, for example:
Go to remix.ethereum.orgâ
Compile Peggy.sol
with solc v0.5.0
Set the environment as Injected Web3 Ropsten
On 'Run' tab, select Peggy and enter "0x22BFD920Ac64B0A90088D07f84137EA79bbb8Ca1"
in 'At Address' field
Select 'At Address' to load the deployed contract
Enter the following for the variables under function lock()
:
_recipient = [HASHED_COSMOS_RECIPIENT_ADDRESS] *(for testuser cosmos1pjtgu0vau2m52nrykdpztrt887aykue0hq7dfh, enter "0x636f736d6f7331706a74677530766175326d35326e72796b64707a74727438383761796b756530687137646668")*_token = [DEPLOYED_TOKEN_ADDRESS]_amount = [WEI_AMOUNT]
Enter the same number from _amount
as the transaction's value (in wei)
Select "transact" to send the lock()
transaction
Then, wait for the transaction to confirm and mine, and for the relayer
to pick it up. You should see the successful output in the relayer
console. You can also confirm the tokens have been minted by using the CLI again:
fbcli query account cosmos1pjtgu0vau2m52nrykdpztrt887aykue0hq7dfh --trust-node
The ethbridge
and oracle modules can be used in other cosmos-sdk
applications by copying them into your application's modules folders and including them in the same way as in the example application. Each module may be moved to its own repo or integrated into the core Cosmos-SDK in future, for easier usage.
There are 2 nuances you need to be aware of when using these modules in other Cosmos-SDK projects.
A specific version of golang.org/x/crypto
(ie tendermint/crypto
) is needed for compatability with go-ethereum
. See the Gopkg.toml
for constraint details. There is an open pull request to tendermint/crypto
to add compatibility, but until that is merged you need to use the customized version (https://github.com/tendermint/crypto/pull/1)
The govendor
steps in the application as above are needed
For instructions on building and deploying the smart contracts, see here.