Is there some analogue ow web3.js in Secret Network?

is there some analogue ow web3.js in Secret Network? And if yes is there any example of how to get token balance? Thanks!

i have created secretjs.js with browserify but when i trying to connect to node i get:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://api.secretapi.io/node_info. (Reason: CORS request did not succeed)

the code i use is

const main = async () => {
// Create connection to DataHub Secret Network node
const client = new secretjs.CosmWasmClient(‘https://api.secretapi.io/’)

  // Query chain ID
  const chainId = await client.getChainId()

  // Query chain height
  const height = await client.getHeight()

  console.log("ChainId:", chainId);
  console.log("Block height:", height);

  console.log('Successfully connected to Secret Network');

}

main().then(resp => {
console.log(resp);
}).catch(err => {
console.log(err);
})

what i can do?

Hi guys, please checkout GitHub - scrtlabs/secret.js: The JavaScript SDK for Secret Network

CORS errors is something that you need to sort out with your node provider.

Hello, Thanks for your answer. One more question is there any RPC service (like infura for ETH) that i can use? Thanks!

1 Like

Yes, Secret Network DataHub - Figment - Building Web 3

Ok i give up, what i trying to achieve is simply check wallet balance with javascript to do so i trying to use this code:

const main = async () => {
// Create connection to DataHub Secret Network node
console.log(‘before connection’);
const client = new secretjs.CosmWasmClient(‘http://chainofsecrets.secrettestnet.io:26657/’)

console.log(‘after connection’);
// Query chain ID
const chainId = await client.getChainId()

  // Query chain height
  const height = await client.getHeight()
  console.log(walletAddress);
  const account = await client.getAccount(walletAddress);

  console.log("ChainId:", chainId);
  console.log("Block height:", height);
  console.log("Account", account);

  console.log('Successfully connected to Secret Network');

}

main().then(resp => {
console.log(resp);
}).catch(err => {
console.log(err);
})

i have tried every RPC url i can find on internet the only that worked was :http://bootstrap.supernova.enigma.co:1317
but this one for testnet. Where i can find mainnet RPC node url? Thanks!

With that version of secretjs you need to use the LCD endpoint, you got one in your figment account

Works) THANKS Assafmo!

1 Like