Skip to content

Instantly share code, notes, and snippets.

@gebv
Last active June 7, 2022 11:24
Show Gist options
  • Save gebv/b1234b45862a4b8e3e124e169bb57c2b to your computer and use it in GitHub Desktop.
Save gebv/b1234b45862a4b8e3e124e169bb57c2b to your computer and use it in GitHub Desktop.
USDT for Crypto Punk. How create new wallet and uses for regular cases.

USDT can be different

  • USDT ERC20 - Ethereum (ETH) network. Hex address start with 0x...
  • USDT BEP20 - Binance Smart Chain (BSC) network. Hex address start with 0x...
  • USDT TRC20 - TRON network. Hex address start with T... (?)

How create new wallet for USDT ERC20 and USDT BEP20?

BEP20 and BEP20 based on ETH. This means that the BSC address is the same as in ETH only on different networks

Following example code in Go (use playground execute result with caution)

Try the playground (source code in Go)

How view details at the address?

For BEP20 https://bscscan.com/address/0x71b959A205559e6a748BA2A29BEB5847Af0FdBc9#tokentxns

For ERC20

? https://ethplorer.io/ru/address/0x71b959A205559e6a748BA2A29BEB5847Af0FdBc9

How view status by transactions?

For BEP20 https://bscscan.com/tx/0x55153d877d2bcfc2405fc08520e770ad6f9d6dc92b37203ff4f7ccfe3f7dc299

For ERC20

? https://ethplorer.io/ru/tx/0x55153d877d2bcfc2405fc08520e770ad6f9d6dc92b37203ff4f7ccfe3f7dc299

For experts. How quickly replace wrong transactions?

TODO

For experts. How generate new wallet in linux console?

TODO

$ openssl rand -hex 32
84e0956c49fc49a9bb4d81b81a26203b4095b483e39dadc73d9fee7351489eb0

Tx Fee

Tx Fee In USD = GasPrice(gwei) * GasUsed * XXX_USD_rate.

For XXX_USD_rate

  • bsc BNB = 5Gwei
  • eth ? ~~ 20Gwei
  • tron TRX ?

Links

// You can edit this code!
// Click here and start typing.
package main
import (
"crypto/ecdsa"
"crypto/sha256"
"encoding/hex"
"fmt"
"strings"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/mr-tron/base58"
)
func main() {
priv := newPrivKey()
showPrivDetails(priv)
fmt.Println()
showEthDetails(priv)
fmt.Println()
showTronDetails(priv)
fmt.Println()
fmt.Println()
fmt.Println("Restore from Private Key")
newPriv := privFromHex(privKeyHex(priv))
showPrivDetails(newPriv)
fmt.Println()
showEthDetails(newPriv)
fmt.Println()
showTronDetails(newPriv)
fmt.Println()
}
func showPrivDetails(priv *ecdsa.PrivateKey) {
fmt.Println("Private Key:", privKeyHex(priv))
fmt.Println("Public Key:", pubKeyHex(priv))
}
func showTronDetails(priv *ecdsa.PrivateKey) {
tron := &TronWallet{priv}
fmt.Println("Tron")
tronAddrHex, tronAddrb58 := tron.Addr()
fmt.Println("Addr Hex:", tronAddrHex)
fmt.Println("Addr Base58:", tronAddrb58)
}
func showEthDetails(priv *ecdsa.PrivateKey) {
eth := &EthWallet{priv}
fmt.Println("Ethereum")
fmt.Println("Addr:", eth.Addr())
}
type EthWallet struct {
priv *ecdsa.PrivateKey
}
// Addr returns the address in hex format
func (w *EthWallet) Addr() string {
return w.addr().String()
}
func (w *EthWallet) addr() common.Address {
return crypto.PubkeyToAddress(w.priv.PublicKey)
}
func (w *EthWallet) addrN(n int) common.Address {
return crypto.CreateAddress(w.addr(), uint64(n))
}
func (w *EthWallet) AddrN(n int) string {
return w.addrN(n).String()
}
type TronWallet struct {
priv *ecdsa.PrivateKey
}
// Addr returns the address in hex (begins with 41) and base58 (begins with T) format
func (w *TronWallet) Addr() (string, string) {
address := crypto.PubkeyToAddress(w.priv.PublicKey).Hex()
address = "41" + address[2:]
s256 := func(in []byte) []byte {
h := sha256.New()
h.Write(in)
b := h.Sum(nil)
return b
}
addb, _ := hex.DecodeString(address)
hash1 := s256(s256(addb))
secret := hash1[:4]
for _, v := range secret {
addb = append(addb, v)
}
return address, base58.Encode(addb)
}
func newPrivKey() *ecdsa.PrivateKey {
priv, err := crypto.GenerateKey()
if err != nil {
panic(err)
}
return priv
}
func pubKeyHex(priv *ecdsa.PrivateKey) string {
return "0x" + hex.EncodeToString(crypto.FromECDSAPub(&priv.PublicKey))
}
func privKeyHex(priv *ecdsa.PrivateKey) string {
return "0x" + hex.EncodeToString(crypto.FromECDSA(priv))
}
func privFromHex(in string) *ecdsa.PrivateKey {
h, err := hex.DecodeString(strings.TrimPrefix(in, "0x"))
if err != nil {
panic(err)
// BOOM
}
priv, err := crypto.ToECDSA(h)
if err != nil {
panic(err)
// BOOM
}
return priv
}
@0fuz
Copy link

0fuz commented Jun 7, 2022

https://gist.github.com/gebv/b1234b45862a4b8e3e124e169bb57c2b#how-view-details-at-the-address

https://gist.github.com/gebv/b1234b45862a4b8e3e124e169bb57c2b#for-experts-how-quickly-replace-wrong-transactions

  • Need replace tx with same nonce but higher gasPrice untill tx in mempool and not mined.
  • For ETH its minutes
  • For BSC its 2blocks or 6seconds

https://gist.github.com/gebv/b1234b45862a4b8e3e124e169bb57c2b#for-experts-how-generate-new-wallet-in-linux-console

  • any 64len hex string could be used as privateKey

https://gist.github.com/gebv/b1234b45862a4b8e3e124e169bb57c2b#tx-fee

  • BSC, 5gwei, regular BNB transfer tx: (5gwei*21000gasUsed*284$/1bnb) /1e18 = 5 000 000 000 * 21 000 * 284 / e18 = 0.000105bnb = ~0.03$

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment