Git Product home page Git Product logo

tron-wallet's Introduction

tron-wallet

tron wallet package for creating and generating wallet, transferring TRX, getting wallet balance and crawling blocks to find wallet transactions

Installation

go get github.com/ranjbar-dev/[email protected]

Test

test for Crawler, TronWallet and Token located at /test

go test ./test

Wallet methods

  • generating tron wallet
w := GenerateTronWallet(enums.SHASTA_NODE)
w.Address // strnig 
w.AddressBase58 // strnig 
w.PrivateKey // strnig 
w.PublicKey // strnig 
  • creating tron wallet from private key
w := CreateTronWallet(enums.SHASTA_NODE,privateKeyHex)
w.Address // strnig 
w.AddressBase58 // strnig 
w.PrivateKey // strnig 
w.PublicKey // strnig 
  • getting wallet trx balance
balanceInSun,err := w.Balance()
balanceInSun // int64 
  • getting wallet trc20 balance
balanceInToken,err := w.BalanceTRC20(token)
balanceInToken // int64 
  • crawl blocks for addresses transactions

c := &Crawler{
		Node: enums.SHASTA_NODE, // network -> maninet, shasta, nile
		Addresses: []string{
			"TY3PJu3VY8xVUc5BjYwJtyRgP7TfivV666", // list of your addresses
		},
	}
	
res, err := c.ScanBlocks(40) // scan latest 40 block on block chain and extract addressess transactions 
res, err := c.ScanBlocksFromTo(28905305, 28905307) // or scan block from to number
Example 
// *
{
    {
        "address": "TY3PJu3VY8xVUc5BjYwJtyRgP7TfivV666",
        "tranasctions": {
            {
                "tx_id": "6afbc5758d49e8d8bedddd903edbfc01c5f11ebfbaa6237e887294a6fc9394a2",
                "from_address": "TJnsY5bGiwuPCQFismQDwyVTPAn7M88888",
                "to_address": "TY3PJu3VY8xVUc5BjYwJtyRgP7TfivV666",
                "amount": "195500", // sun
                "confirmations": 1,
                "symbol": "TRX",
            },
            {
                "tx_id": "61624fffb31d09b9fe7252cd743733a5890c2a9077698d4a9bcb3d70ebb28777",
                "from_address": "TSw5FSuWhTAcaJmBUVFY9fUY4ihwx588b6",
                "to_address": "TJnsY5bGiwuPCQFismQDwyVTPAn7M88888",
                "amount": "10000", // in token sub value 
                "confirmations": 1,
                "symbol": "USDT",
            },
        }
    },
    ...
}
* // 
	

Estimate transfer trx fee

feeInSun,err := w.EstimateTransferFee("TJnsY5bGiwuPCQFismQDwyVTPAn7M88888",10000)
feeInSun // int64

Estimate transfer trc20 fee

feeInSun,err := w.EstimateTransferTRC20Fee()
feeInSun // int64
  • transfer trx from wallet
txId, err := w.Transfer(toAddressBase58, amount)
txId // string 
  • transfer trc20 from wallet
txId, err := w.TransferTRC20(token, toAddressBase58, amount)
txId // string 

Token methods

  • declaring token
token := &tronWallet.Token{
    ContractAddress: enums.SHASTA_Tether_USDT,
}
  • Getting token name
token.GetName(w.Node, w.AddressBase58) // return string,error
  • Getting token symbol
token.GetSymbol(w.Node, w.AddressBase58) // return string,error
  • Getting token decimals
token.GetDecimal(w.Node, w.AddressBase58) // return int64,error

Supported networks

check enums/nodes file alternatively you can create your own node

node := enums.CreateNode("grpc.test.com:50051")

Supported contracts

check enums/contracts file alternatively you can create your own contract

contractAddress := enums.CreateContractAddress("TPYmHEhy5n8TCEfYGqW2rPxsghSfzghPDn")

TRX Faucet

Follow TronTestnet Twitter account @TronTest2 . Write your address in your tweet and @TronTest2 . They will transfer 10,000 test TRX (usually within five minutes). Each address can only be obtained once a day. If you need TRX for the nile testnet, please add "NILE" in your tweet.

TRC20 Faucet

Go to https://developers.tron.network/ and connect to the discord community. You can than ask for usdt in #faucet channel. Just type !shasta_usdt YOUR_WALLET_ADDRESS and send. TronFAQ bot will send you 5000 USDT (SASHTA) soon.

Important

I simplified this repository https://github.com/fbsobreira repository to create this package You can check go tron sdk for better examples and functionalities and do not use this package in production, I created this package for education purposes.

Donation

Address TUE66D1BT79FQcJE7fwf5vdfu3BYM4ph9Y

tron-wallet's People

Contributors

ranjbar-dev avatar capitgit avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.