Giter Site home page Giter Site logo

tronweb's Introduction

TronWeb

TronWeb is an iOS toolbelt for interaction with the Tron network.

language Support  CocoaPods

For more specific usage, please refer to the demo

Installation with CocoaPods

Add this to your podfile and run pod install to install:

pod 'TronWeb', '~> 1.1.5'

Swift Package Manager

The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler.

Once you have your Swift package set up, adding TronWeb as a dependency is as easy as adding it to the dependencies value of your Package.swift.

dependencies: [
    .package(url: "https://github.com/james19870606/TronWeb.git", .upToNextMajor(from: "1.1.5"))
]

Example usage

import TronWeb
Setup TronWeb3
let tronWeb = TronWeb3()
let privateKey = ""
let TRONApiKey = ""
if tronWeb.isGenerateTronWebInstanceSuccess != true {
    tronWeb.setup(privateKey: privateKey, node: chainType == .main ? TRONMainNet : TRONNileNet) { [weak self] setupResult,error in
        guard let self = self else { return }
        if setupResult {
        //......
        } else { 
          print(error)
        }
    }
} else {
        //......

}
Create Random
tronWeb.createRandom { [weak self] state, address, privateKey, publicKey, mnemonic, error in
    guard let self = self else { return }
    self.createRandomBtn.isEnabled = true
    tipLabel.text = "create finished."
    if state {
        let text =
            "address: " + address + "\n\n" +
            "mnemonic: " + mnemonic + "\n\n" +
            "privateKey: " + privateKey + "\n\n" +
            "publicKey: " + publicKey
        walletDetailTextView.text = text
    } else {
        walletDetailTextView.text = error
    }
}
Create Account
tronWeb.createAccount { [weak self] state, base58Address, hexAddress, privateKey, publicKey, error in
    guard let self = self else { return }
    self.createAccountBtn.isEnabled = true
    tipLabel.text = "create finished."
    if state {
        let text =
            "base58Address: " + base58Address + "\n\n" +
            "hexAddress: " + hexAddress + "\n\n" +
            "privateKey: " + privateKey + "\n\n" +
            "publicKey: " + publicKey
        walletDetailTextView.text = text
    } else {
        walletDetailTextView.text = error
    }
}
Import Account From Mnemonic
tronWeb.importAccountFromMnemonic (mnemonic: mnemonic){ [weak self] state, address, privateKey, publicKey, error in
    guard let self = self else { return }
    self.importAccountFromMnemonicBtn.isEnabled = true
    tipLabel.text = "import finished."
    if state {
        let text =
            "address: " + address + "\n\n" +
            "privateKey: " + privateKey + "\n\n" +
            "publicKey: " + publicKey
        walletDetailTextView.text = text
    } else {
        walletDetailTextView.text = error
    }
}
Send TRX
let remark = ""
let toAddress = ""
let amountText = "1" // This value is 0.000001 
tronWeb.trxTransferWithRemark(remark: remark,
                                      toAddress: toAddress,
                                      amount: amountText){ [weak self] (state, txid,error) in
    guard let self = self else { return }
    print("state = \(state)")
    print("txid = \(txid)")
    if (state) {
        self.hashLabel.text = txid
    } else {
        self.hashLabel.text = error
    }
}
Send TRC20
let remark = ""
let toAddress = ""
let amountText = "1" // This value is 0.000001 
let trc20Address = ""
tronWeb.trc20TokenTransfer(toAddress: toAddress,
                           trc20ContractAddress: trc20Address, amount: amountText,
                           remark: remark,
                           feeLimit: "100000000") { [weak self] (state, txid,error) in
    guard let self = self else { return }
    print("state = \(state)")
    print("txid = \(txid)")
    if (state) {
        self.hashLabel.text = txid
    } else {
        self.hashLabel.text = error
    }
}

更详细的使用方法,建议参考 demo

License

TronWeb is released under the MIT license. See LICENSE for details.

tronweb's People

Contributors

james19870606 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

tronweb's Issues

Owneraddress

Where is the Owneraddress ??i got an error is" no owneraddress"

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.