Hello,
I’ve deployed a smart contract on the Zama Network and I want the web app interacts with the SC to show and use decrypted data.
The error is this:
“Uncaught (in promise) Error: An error occurred during decryption at Object.reencrypt”.
Can you please help me?
Thanks in advance.
I’ve deployed my contract through remix, I’m using metamask, and I’ve installed fhevm through node.js. So i’m working with javascript.
This is the code of the view function in the SC:
function getSEI(uint supplier_id) public view returns (euint32) {
Supplier storage supplier = Suppliers[supplier_id];
return supplier.SEI_index;
}
When calculating the score i’ve implemented the logic for allowing the permanent access to this index to both the contract and msg.sender.
(Just to specify, in Remix everything works well!)
This is the code of my web app:
useEffect(() => {
if (window.ethereum){
initFhevm().then(async () => {
const _instance= await createInstance({
aclAddress: '0x2Fb4341027eb1d2aD8B5D9708187df8633cAFA92',
chainId: 9000,
networkUrl: "https://devnet.zama.ai/",
gatewayUrl: "https://gateway.devnet.zama.ai",
});
setInstance(_instance);
});
} else {
alert("Non-ethereum browser detected. Install Metamask and try again");
}
return () => {};
}, []);
const getDecryptedsei = async () => {
const provider = new BrowserProvider(window.ethereum);
const contractAddress = "0x0327719b1CDB97FC5E2aB514beDf51a50FaEb18D";
const account_ = "0xE518AfAc620D26749A0fBC46C08A8D4c14233beC";
const {publicKey: publicKey_, privateKey: privateKey_} = instance.generateKeypair();
const eip712_ = instance.createEIP712(publicKey_, contractAddress);
//USER_ADDRESS
const params_ = [account_, JSON.stringify(eip712_)];
const signature_ = await window.ethereum.request({ method: "eth_signTypedData_v4", params: params_ });
const contract= new Contract(contractAddress, abi, account_).connect(provider);
const encryptedSEI_ = await contract.getSEI(supplier_id);
const decrypted_SEI = await instance.reencrypt(encryptedSEI_, privateKey_,publicKey_, signature_, contractAddress, account_);
console.log(decrypted_SEI);
};
Thanks in advance