Querying Secret contracts

Learn how to query Secret Network smart contract on EVM with secret-network-ccl npm package

With querySecretContract you can query any SecretPath-compatible smart contract on Secret Network.

For this example, we are going to query the key value store contract on Secret Network.

querySecretContract requires the Secret contractAddress, codeHash, network, handle (ie the name of the query function you want to query in the Secret Network contract), and any parameters needed for the query, which in this case is password.

const {querySecretContract} = require('./node_modules/secret-network-ccl')
const dotenv = require('dotenv');
dotenv.config();

const contractAddress = "secret1s79j3uaa0g49ncur884vv80ucz7hdwgltgke52";
const contractCodeHash = "f0947ac3d0459bd5ccc24a43aa18762325f7582dc7919b4557ecf98b81345261";
let password = { password: "2" }
let handle = "retrieve_data";
let network = "testnet";
//use "mainnet" for network if contract is deployed on Secret mainnet

querySecretContract(  contractAddress, contractCodeHash, network, handle, password); 

Call the function to execute a Secret Network smart contract on EVM. If you pass the correct password, the Secret contract will return your data:

{ data: 'secret rules!' }

Last updated