Skip to content

Instantly share code, notes, and snippets.

@fredead
Last active September 9, 2016 08:22
Show Gist options
  • Save fredead/182f0efa5f346e960175902faba0fab6 to your computer and use it in GitHub Desktop.
Save fredead/182f0efa5f346e960175902faba0fab6 to your computer and use it in GitHub Desktop.
Ethereum compile with solc and deploy using geth
#!/bin/sh -e
TEMPDIR=`mktemp -d`
echo Compilecode
solc --gas --bin -o ${TEMPDIR} $1
FILENAME=${TEMPDIR}/$1
FILENAME=`echo ${TEMPDIR}/$1 | sed -e 's/.sol$/.bin/'`
DATA=`cat $FILENAME`
echo "Unlock account"
geth --exec 'personal.unlockAccount(eth.coinbase)' attach ipc:/opt/geth/geth.ipc
TRANSACTIONID=`geth --exec "eth.sendTransaction({from: eth.coinbase, \"gas\": \"0x220000\", \"data\": \"0x${DATA}\" })" attach ipc:/opt/geth/geth.ipc`
echo "transaction completed is ${TRANSACTIONID}"
sleep 50
geth --exec "eth.getTransactionReceipt(${TRANSACTIONID})" attach ipc:/opt/geth/geth.ipc | grep contractAddress
rm -Rf ${TEMPDIR}
# Calling a contract
# get abi
# solc --abi *.so
# This generates a file use contents with contractAddress about in geth
# > var MyContract = eth.contract(<contents of abi file above).at(<contractAddress>)
# now to call
# Mycontract.<function>(var1,var2,...., { from: <fromhash> })
# Mycontract.<function>.sendTransaction(var1,var2,...., { from: <fromhash> })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment