question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

contract balanceOf call, response "owner_address isn't set."

See original GitHub issue
// init tronWeb
const TronWeb = require('tronweb')

const tronWeb = new TronWeb({
  fullNode: 'https://api.trongrid.io',
  solidityNode: 'https://api.trongrid.io',
})

// read trc20 account balance
let contract = await tronWeb.contract().at("TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t"); 
let result = await contract.balanceOf('TZ13rQk53DDvK2pR4nfBLyuYTR4EGAFBwT').call();

// response error
//(node:49919) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 14): class java.security.InvalidParameterException : owner_address isn't set

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:6

github_iconTop GitHub Comments

13reactions
joadrcommented, Jul 26, 2021

Why would you need to set an address for calling a balanceOf?

10reactions
keesdewit82commented, Aug 25, 2020

Setting the private key is not a great advise to be honest. You should try to avoid keeping your private key available as a string in your application. Keep it on a secure device for example. Not in the memory of your software. Anyway, this issue can also be fixed by applying the following code:

tronWeb.setAddress('TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t');

So that would be:

const TronWeb = require('tronweb')

const tronWeb = new TronWeb({
  fullNode: 'https://api.trongrid.io',
  solidityNode: 'https://api.trongrid.io',
})

// set the owner address
tronWeb.setAddress('TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t');

// read trc20 account balance
let contract = await tronWeb.contract().at("TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t"); 
let result = await contract.balanceOf('TZ13rQk53DDvK2pR4nfBLyuYTR4EGAFBwT').call();```
Read more comments on GitHub >

github_iconTop Results From Across the Web

tokens - Unable to call ERC20's balanceOf() from another ...
Found the answer. The problem was the require() state in the balanceOf function. The balanceOf function does not need transaction, ...
Read more >
Two ways of getting balance in Solidity - Stack Overflow
I understand the first one is just go to an address and get its balance. I don't get how come mapping(address => uint)...
Read more >
HackPedia: 16 Solidity Hacks/Vulnerabilities, their Fixes and ...
This attack can occur when a contract sends ether to an unknown address. ... function is called in the wallets constructor and sets...
Read more >
ERC-20 Contract Walk-Through - ethereum.org
function transfers a tokens from the caller to a different address. This involves a change of state, so it isn't a view ....
Read more >
Questions and Answers: The IMF's response to COVID-19
Where can countries get help if financing provided by the IMF isn't enough? What economic policy actions have countries already taken to address...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found