go/eth_tx_form.go
package main
import(
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"math/big"
"strconv"
"encoding/hex"
"strings"
)
func genSignedTx(chainIdStr string, nonceStr string, valueStr string, gasLimitStr string, toStr string, dataStr string, gasPriceStr string, privKeyStr string) (map[string]string, error) {
var thisError error
response := make(map[string]string)
chainId := chainIdStr
privKey, _ := crypto.HexToECDSA(privKeyStr)
to := common.HexToAddress(toStr)
nonce, _ := strconv.ParseUint(nonceStr, 10, 64)
gasLimit, _ := strconv.ParseUint(gasLimitStr,10,64)
value, _ := new(big.Int).SetString(EthToWei(valueStr),10)
gasPrice, _ := new(big.Int).SetString(GweiToWei(gasPriceStr),10)
signer := types.LatestSigner( getChainsConfig()[chainId] )
data, _ := hex.DecodeString(strings.TrimPrefix(dataStr, "0x"))
tx := types.NewTransaction(uint64(nonce), to, value, gasLimit, gasPrice, data)
signedTx, _ := types.SignTx(tx, signer, privKey)
rawTx, _ := signedTx.MarshalBinary()
response["hash"] = signedTx.Hash().Hex()
response["rawTx"] = hex.EncodeToString(rawTx)
return response, thisError
}
go/templates/eth_tx_form.html
{{ template "html_iframe_header.html" .}}
{{if .error}}
<div class="alert alert-danger">
<strong>Error!</strong> {{ .error }}
</div>
{{else if .rawTx}}
<div class="alert alert-success">
<h6 class="mt-3">Final TX Hex</h6>
<textarea class="form-control" rows="5" id="comment">{{.rawTx}}</textarea>
<p>
{{if eq .chain "1"}}
* <a href="https://etherscan.io/pushTx" target="_blank">https://etherscan.io/pushTx</a>
{{end}}
{{if eq .chain "3"}}
* <a href="https://ropsten.etherscan.io/pushTx" target="_blank">https://ropsten.etherscan.io/pushTx</a>
{{end}}
</p>
<h6 class="mt-3">TX Hash</h6>
<input class="form-control" readonly value="{{.hash}}"/>
</div>
{{end}}
<form action='{{.queryString}}' method='post'>
<div class="form-group">
<label for="chain">Chain:</label>
<select id="chain" name="chain" class="form-control"{{/*<?php echo in_array("chain", $disableFields) ? " readonly" : ""?>*/}}>
{{ $chain := .chain }}
{{if not $chain}}
{{$chain = ""}}
{{end}}
{{ range $key, $value := .chains }}
<option value='{{$key}}'
{{if eq $chain $key}}
selected
{{end}}
>{{$value}}</option>
{{end}}
</select>
</div>
<div class="form-group">
<label for="nonce">Nonce:</label>
<input class="form-control" type='text' name='nonce' id='nonce' value='{{.nonce}}' {{/*<?php echo in_array("nonce", $disableFields) ? " readonly" : ""?>*/}}>
<small>
Learn more <a href='eth_tx_nonce.php' target='_blank'>here</a>.
</small>
</div>
<div class="form-group">
<label for="gas_price">Gas Price:</label>
<div class="input-group mb-3">
<input class="form-control" type='text' name='gas_price' id='gas_price' value='{{.gas_price}}' {{/*<?php echo in_array("gas_price", $disableFields) ? " readonly" : ""?>*/}}>
<div class="input-group-append">
<span class="input-group-text">GWEI</span>
</div>
</div>
</div>
<div class="form-group">
<label for="gas_limit">Gas Limit:</label>
<input class="form-control" type='text' name='gas_limit' id='gas_limit' value='{{.gas_limit}}' {{/*<?php echo in_array("gas_limit", $disableFields) ? " readonly" : ""?>*/}}>
</div>
<div class="form-group">
<label for="to">To:</label>
<input placeholder="Address" class="form-control" type='text' name='to' id='to' value='{{.to}}' {{/*<?php echo in_array("to", $disableFields) ? " readonly" : ""?>*/}}>
</div>
<div class="form-group">
<label for="data">Data (Hex):</label>
<input class="form-control" type='text' name='data' id='data' value='{{.data}}' {{/*<?php echo in_array("data", $disableFields) ? " readonly" : ""?>*/}}>
</div>
<div class="form-group">
<label for="value">ETH Value:</label>
<div class="input-group mb-3">
<input class="form-control" type='text' name='value' id='value' value='{{.value}}' {{/*<?php echo in_array("value", $disableFields) ? " readonly" : ""?>*/}}>
<div class="input-group-append">
<span class="input-group-text">ETH</span>
</div>
</div>
</div>
<div class="form-group">
<label for="privkey">From:</label>
<input placeholder="Sender's Private Key (Hex)" class="form-control" type='text' name='privkey' id='privkey' value='{{.privkey}}' {{/*<?php echo in_array("privkey", $disableFields) ? " readonly" : ""?>*/}}>
</div>
<input type='submit' class="btn btn-success btn-block"/>
</form>
{{ template "html_iframe_footer.html" .}}