Function getAccountBalance() doesn't work
I am creating examples to share with another developers but i try to keep for now very simple the code, all the basic functions are working:
I am using the oficial documentation.LINK
account.deleteAccount()
account.getAccountDetails()
account.createAccount()
etc... but this function:
account.getAccountBalance();
Send me a error:
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading "storage_amount _per_byte" )
at Account.getAccountBalance (VM3453 near-api-is.is:346)
at async main.is: 46
+++++UPDATE++++++
const CONTRACT_NAME = 'josedlujan.testnet'; /* TODO: fill this in! */
const config = {
nodeUrl: "https://rpc.testnet.near.org",
//deps: {
keyStore: new nearApi.keyStores.BrowserLocalStorageKeyStore(),
//},
networkId: 'testnet',
nodeUrl: 'https://rpc.testnet.near.org',
contractName: CONTRACT_NAME,
walletUrl: 'https://wallet.testnet.near.org',
helperUrl: 'https://helper.testnet.near.org'
};
async function () {
window.near = await nearApi.connect(config);
console.log(near)
// ---------------------------------------------------------------------------
// here you have access to `near-api-js` and a valid connection object `near`
// ---------------------------------------------------------------------------
window.walletConnection = new nearApi.WalletConnection(near);
console.log(window.walletConnection)
// Initializing our contract APIs by contract name and configuration.
window.contract = await new nearApi.Contract(window.walletConnection.account(), near.contractName, {
// View methods are read-only – they don't modify the state, but usually return some value
viewMethods: ['get_num'],
// Change methods can modify the state, but you don't receive the returned value when called
changeMethods: ['increment', 'decrement', 'reset'],
// Sender is the account ID to initialize transactions.
// getAccountId() will return empty string if user is still unauthorized
sender: window.walletConnection.getAccountId()
});
window.account = await near.account(walletConnection.getAccountId());
console.log(window.account);
const balance = await window.account.getAccountBalance();
console.log(balance);
I found the solution. The problem is the documentation is some documents refers to different versions of the API, the first documentation that I consult uses API 36 with which I show the error, in another example as I paste on the screen they use version 41: I had to look for the last ncd on my own and use version 44. LINK
The recommendation is always be careful with the versions some documentation needs an update.
Be careful when you find specific errors with values of the variables that are not parameters that are requested since it is very likely that the documentation you use is not updated, thanks Sherif for the support and John too.
NCD