Writing Encrypted Data to Contract
This page covers the “encrypt → write tx” flow: encrypt plaintext values into InE* structs and pass them directly into a contract call.
encryptInputs returns EncryptedItemInput objects that match the Solidity InE* input structs. The on-chain CoFHE library validates the verifier signature before the contract can use the ciphertext.
The flow is as follows:
- Ensure your contract function accepts encrypted
InE*parameters. - Encrypt the plaintext values with
encryptInputs. - Send a transaction and pass the encrypted structs as the
InE*arguments.
Prerequisites
-
Create and connect a client (see the client page).
-
Your contract function must accept encrypted
InE*structs.
The encrypted type you choose in JavaScript/TypeScript must match the Solidity parameter type:
Encryptable.uint32(...)→InEuint32Encryptable.bool(...)→InEboolEncryptable.address(...)→InEaddress
Example: encrypt and call a contract
The reference contract used throughout these docs is EncryptedCounter.sol. It exposes setCount(InEuint32) which is the canonical “encrypt input → send in the same transaction” flow.
Solidity
// From EncryptedCounter.sol (see /reference/encrypted-counter-sol)
function setCount(InEuint32 memory _inCount) external onlyOwner {
count = FHE.asEuint32(_inCount);
FHE.allowThis(count);
FHE.allowSender(count);
decrypted = false;
decryptedCount = 0;
}Common pitfalls
- Wrong
Encryptabletype: theEncryptable.*factory must match the Solidity parameter type (InEuint32vsInEuint64, etc). - Wrong account / chain: encrypted inputs are authorized for a specific
account + chainId. If you encrypt under the wrong wallet/network, the contract call may revert. - ABI struct shape mismatch: if you hand-write an ABI, ensure the tuple fields are
(ctHash, securityZone, utype, signature)in the same order your client library expects.