Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Method To Return TRC20 Balance #154

Merged
merged 7 commits into from
Sep 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tatumio/tatum",
"version": "1.25.7",
"version": "1.25.8",
"description": "Tatum API client allows browsers and Node.js clients to interact with Tatum API.",
"main": "dist/src/index.js",
"repository": "https://github.com/tatumio/tatum-js",
Expand Down
38 changes: 30 additions & 8 deletions src/transaction/tron.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import {AxiosRequestConfig} from 'axios';
import { AxiosRequestConfig } from 'axios';
import BigNumber from 'bignumber.js';
import {tronBroadcast} from '../blockchain';
import {axios, validateBody} from '../connector/tatum';

import {TATUM_API_URL} from '../constants';
import {listing} from '../contracts/marketplace';
import { tronBroadcast } from '../blockchain';
import { axios, validateBody } from '../connector/tatum';
import { TATUM_API_URL } from '../constants';
import { listing } from '../contracts/marketplace';
import abi from '../contracts/trc20/token_abi';
import bytecode from '../contracts/trc20/token_bytecode';
import trc721_abi from '../contracts/trc721/trc721_abi';
Expand All @@ -26,9 +25,10 @@ import {
TronMintMultipleTrc721,
TronMintTrc721,
TronTransferTrc721,
TronUpdateCashbackTrc721,
TronUpdateCashbackTrc721
} from '../model';
import {obtainCustodialAddressType} from '../wallet';
import { obtainCustodialAddressType } from '../wallet';


// tslint:disable-next-line:no-var-requires
const TronWeb = require('tronweb');
Expand Down Expand Up @@ -296,6 +296,28 @@ export const prepareTronTrc10SignedTransaction = async (testnet: boolean, body:
return JSON.stringify(await tronWeb.trx.sign(tx, fromPrivateKey))
}

/**
* Get TRC20 balance for the given tron address.
* @param testnet mainnet or testnet version
* @param address the address whose balance is returned
* @param contractAddress the TRC20 contract address
* @param provider
*/
export const tronGetAccountTrc20Address = async (
testnet: boolean,
address: string,
contractAddress: string,
provider?: string,
) => {
if (!contractAddress) {
throw new Error('Contract address not set.');
}
const tronWeb = prepareTronWeb(testnet, provider);
tronWeb.setAddress(contractAddress);
const contractInstance = await tronWeb.contract().at(contractAddress);
return await contractInstance.balanceOf(address).call();
};

export const getTronTrc20ContractDecimals = async (testnet: boolean, contractAddress: string, provider?: string) => {
if (!contractAddress) {
throw new Error('Contract address not set.')
Expand Down