Skip to content

Instantly share code, notes, and snippets.

@horeaporutiu
Last active March 19, 2019 23:28
Show Gist options
  • Save horeaporutiu/e57d05d33ea91dc3954c8a51510cf87c to your computer and use it in GitHub Desktop.
Save horeaporutiu/e57d05d33ea91dc3954c8a51510cf87c to your computer and use it in GitHub Desktop.
fabricEvmCommands.txt
./byfn.sh down
./byfn.sh up
docker exec -it cli bash
**next commands are run from the peer cli**
export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
export CORE_PEER_ADDRESS=peer0.org1.example.com:7051
export CORE_PEER_LOCALMSPID="Org1MSP"
export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
*install cc
peer chaincode install -n evmcc -l golang -v 0 -p github.com/hyperledger/fabric-chaincode-evm/evmcc
*instantiate
peer chaincode instantiate -n evmcc -v 0 -C mychannel -c '{"Args":[]}' -o orderer.example.com:7050 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
**in a different terminal window**
export FAB3_CONFIG=${GOPATH}/src/github.com/hyperledger/fabric-chaincode-evm/examples/first-network-sdk-config.yaml # Path to a compatible Fabric SDK Go config file
export FAB3_USER=User1 # User identity being used for the proxy (Matches the users names in the crypto-config directory specified in the config)
export FAB3_ORG=Org1 # Organization of the specified user
export FAB3_CHANNEL=mychannel # Channel to be used for the transactions
export FAB3_CCID=evmcc # ID of the EVM Chaincode deployed in your fabric network
export PORT=5000 # Port the proxy will listen on. If not provided default is 5000.
make fab3
bin/fab3
**in a different terminal window start node session**
node
> Web3 = require('web3')
> web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:5000'))
> web3.eth.defaultAccount = web3.eth.accounts[0]
> simpleStorageABI = [
{
"constant": false,
"inputs": [
{
"name": "x",
"type": "uint256"
}
],
"name": "set",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "get",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
}
]
> simpleStorageBytecode = '608060405234801561001057600080fd5b5060df8061001f6000396000f3006080604052600436106049576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806360fe47b114604e5780636d4ce63c146078575b600080fd5b348015605957600080fd5b5060766004803603810190808035906020019092919050505060a0565b005b348015608357600080fd5b50608a60aa565b6040518082815260200191505060405180910390f35b8060008190555050565b600080549050905600a165627a7a723058203dbaed52da8059a841ed6d7b484bf6fa6f61a7e975a803fdedf076a121a8c4010029'
> SimpleStorage = web3.eth.contract(simpleStorageABI)
> deployedContract = SimpleStorage.new([], {data: simpleStorageBytecode})
> myContract = SimpleStorage.at(web3.eth.getTransactionReceipt(deployedContract.transactionHash).contractAddress)
> myContract.set(10)
> myContract.get().toNumber()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment