How to use tronweb - 10 common examples

To help you get started, we’ve selected a few tronweb examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TronLink / tronlink-extension / packages / backgroundScript / services / WalletService / index.js View on Github external
async importAccount({ privateKey, name }) {
        // 埋点

        logger.info(`Importing account '${ name }' from popup`);

        const account = new Account(
            privateKey.match(/^T/) && TronWeb.isAddress(privateKey) ? ACCOUNT_TYPE.LEDGER : ACCOUNT_TYPE.PRIVATE_KEY,
            privateKey
        );

        const {
            address
        } = account;

        account.name = name;
        if (Object.keys(this.accounts).length === 0) {
            this.setCache();
        }
        this.accounts[address] = account;
        StorageService.saveAccount(account);

        this.emit('setAccounts', this.getAccounts());
        this.selectAccount(address);
github tronscan / tronscan-frontend / src / components / blockchain / Contract / Code.js View on Github external
constructor(props) {
    super(props);
    // https://api.shasta.trongrid.io
    this.tronWeb = new tronWeb({
      fullNode: 'https://api.trongrid.io',
      solidityNode: 'https://api.trongrid.io',
      eventServer: 'https://api.trongrid.io',
    })
    this.state = {
      loading: true,
      choiceContractItem: 'code',
      contractInfoList: '',
      viewContractList: [],
      payableContractList: [],
      nonePayableContractList: [],
      eventContractList: [],
      currentTokens: [],
      contractVerifyState: true
    };
  }
github tronscan / tronscan-frontend / src / services / api.js View on Github external
import { Client as ApiClient } from "@tronscan/client";
import io from "socket.io-client";
import TronWeb from "tronweb";
import xhr from "axios/index";
import { API_URL } from "../constants.js";
import { setLoginWithAddress } from "../actions/app.js";

const ServerNode = "https://api.trongrid.io";
const HttpProvider = TronWeb.providers.HttpProvider; // This provider is optional, you can just use a url for the nodes instead
const fullNode = new HttpProvider(ServerNode); // Full node http endpoint
const solidityNode = new HttpProvider(ServerNode); // Solidity node http endpoint
const eventServer = ServerNode; // Contract events http endpoint
export const tronWeb = new TronWeb(fullNode, solidityNode, eventServer);

export const Client = new ApiClient(API_URL);

export function buildClient(account) {
  return new ApiClient(API_URL);
}

export function channel(path, options) {
  // return io(process.env.API_URL + path, options);
  return io("https://wlcyapi.tronscan.org/socket.io" + path, options);
  //return io('http://172.16.20.207:20110/socket.io' + path, options);
}

class ApiClient20 {
  constructor() {
    this.apiUrl = "https://api.poloniex.org";
github tronscan / tronscan-frontend / src / reducers / app.js View on Github external
address: passwordToAddress(action.password),
          isOpen: true,
        },
      };
    }

    case LOGIN_PK: {

       Lockr.set("islogin", 0);
       const ServerNode =  SUNWEBCONFIG.MAINFULLNODE;
       const HttpProvider = TronWeb.providers.HttpProvider; // This provider is optional, you can just use a url for the nodes instead
       const fullNode = new HttpProvider(ServerNode); // Full node http endpoint
       const solidityNode = new HttpProvider(ServerNode); // Solidity node http endpoint
       const eventServer = ServerNode; // Contract events http endpoint
       const privateKey = action.privateKey;
       const tronWeb = new TronWeb({
               fullNode,
               solidityNode,
               eventServer,
               privateKey
          }
       );
       const sunWeb = new SunWeb(
          {
              fullNode: ServerNode,
              solidityNode: ServerNode,
              eventServer: ServerNode,
          },
          {
              fullNode: SUNWEBCONFIG.SUNFULLNODE,
              solidityNode: SUNWEBCONFIG.SUNSOLIDITYNODE,
              eventServer: SUNWEBCONFIG.SUNEVENTSERVER,
github tronscan / tronscan-frontend / src / components / blockchain / Transaction / info / SetAccountIdContract.js View on Github external
export default function SetAccountIdContract({contract}){
  // const name = useFetch(contract.hash)
  return(
    
      
      <div>
      {toUtf8(contract.account_id)}
              
            
              
            <table>
          <tbody>
          
          </tbody>
      </table>
          {JSON.stringify(contract.cost) != "{}" &amp;&amp; (
            
          )}
          {contract.signature_addresses &amp;&amp; contract.signature_addresses.length &gt; 1 &amp;&amp; (
            
          )}
          
      </div>
    
  )
}
github TronLink / tronlink-extension / packages / backgroundScript / index.js View on Github external
return resolve({
                                    success: true,
                                    data: signedTransaction,
                                    uuid
                                });
                            }
                            return this.walletService.queueConfirmation({
                                type: CONFIRMATION_TYPE.STRING,
                                hostname,
                                signedTransaction,
                                input
                            }, uuid, resolve);
                        }

                        const contractType = transaction.raw_data.contract[ 0 ].type;
                        const contractAddress = TronWeb.address.fromHex(input.contract_address);
                        const {
                            mapped,
                            error
                        } = await transactionBuilder(Number(chainType) === 1 ? NodeService.sunWeb.sidechain : NodeService.sunWeb.mainchain, contractType, input); // NodeService.getCurrentNode()
                        if(error) {
                            return resolve({
                                success: false,
                                data: 'Invalid transaction provided',
                                uuid
                            });
                        }
                        const signedTransaction = await account.sign(
                            mapped.transaction || mapped,
                            Number(chainType) === 1 ? NodeService.sunWeb.sidechain : NodeService.sunWeb.mainchain
                        );
                        const whitelist = this.walletService.contractWhitelist[ input.contract_address ];
github TronLink / tronlink-extension / packages / backgroundScript / services / WalletService / Account.js View on Github external
_importPrivateKey(privateKey) {
        try {
            if (privateKey.match(/^T/) && TronWeb.isAddress(privateKey)) {
                this.privateKey = null;
                this.address = privateKey;
            } else {
                this.privateKey = privateKey;
                this.address = TronWeb.address.fromPrivateKey(privateKey);
            }
        } catch (ex) { // eslint-disable-line
            throw new Error('INVALID_PRIVATE_KEY');
        }
    }
github tronscan / tronscan-frontend / src / services / api.js View on Github external
import { Client as ApiClient } from "@tronscan/client";
import io from "socket.io-client";
import TronWeb from "tronweb";
import xhr from "axios/index";
import { API_URL } from "../constants.js";
import { setLoginWithAddress } from "../actions/app.js";

const ServerNode = "https://api.trongrid.io";
const HttpProvider = TronWeb.providers.HttpProvider; // This provider is optional, you can just use a url for the nodes instead
const fullNode = new HttpProvider(ServerNode); // Full node http endpoint
const solidityNode = new HttpProvider(ServerNode); // Solidity node http endpoint
const eventServer = ServerNode; // Contract events http endpoint
export const tronWeb = new TronWeb(fullNode, solidityNode, eventServer);

export const Client = new ApiClient(API_URL);

export function buildClient(account) {
  return new ApiClient(API_URL);
}

export function channel(path, options) {
  // return io(process.env.API_URL + path, options);
  return io("https://wlcyapi.tronscan.org/socket.io" + path, options);
  //return io('http://172.16.20.207:20110/socket.io' + path, options);
}
github tronscan / tronscan-frontend / src / reducers / app.js View on Github external
isLoggedIn: true,
          address: passwordToAddress(action.password)
        },
        wallet: {
          type: ACCOUNT_PRIVATE_KEY,
          address: passwordToAddress(action.password),
          isOpen: true,
        },
      };
    }

    case LOGIN_PK: {

       Lockr.set("islogin", 0);
       const ServerNode =  SUNWEBCONFIG.MAINFULLNODE;
       const HttpProvider = TronWeb.providers.HttpProvider; // This provider is optional, you can just use a url for the nodes instead
       const fullNode = new HttpProvider(ServerNode); // Full node http endpoint
       const solidityNode = new HttpProvider(ServerNode); // Solidity node http endpoint
       const eventServer = ServerNode; // Contract events http endpoint
       const privateKey = action.privateKey;
       const tronWeb = new TronWeb({
               fullNode,
               solidityNode,
               eventServer,
               privateKey
          }
       );
       const sunWeb = new SunWeb(
          {
              fullNode: ServerNode,
              solidityNode: ServerNode,
              eventServer: ServerNode,
github TronLink / tronlink-extension / packages / backgroundScript / services / WalletService / index.js View on Github external
const nodes = NodeService.getNodes();

        const connectNode = nodes.nodes[nodes.nodes[nodeID].connect];
        if (!connectNode) {

            this.emit('setNode', {
                node: {
                    fullNode: node.fullNode,
                    solidityNode: node.solidityNode,
                    eventServer: node.eventServer,
                    chain: node.chain
                }
            });

            NodeService.tronWeb = new TronWeb(
                node.fullNode,
                node.solidityNode,
                node.eventServer
            );
        } else {

            this.emit('setNode', {
                    node: {
                        fullNode: node.fullNode,
                        solidityNode: node.solidityNode,
                        eventServer: node.eventServer,
                        chain: node.chain
                    },
                    connectNode: {
                        fullNode: connectNode.fullNode,
                        solidityNode: connectNode.solidityNode,

tronweb

JavaScript SDK that encapsulates the TRON HTTP API

MIT
Latest version published 2 months ago

Package Health Score

84 / 100
Full package analysis