A TypeScript client for incrementing the Counter contract using Predicate signatures.
- Install dependencies:
cd client
npm install- Create a
.envfile with the following variables:
# Predicate API configuration
PREDICATE_API_KEY=your_predicate_api_key_here
# Blockchain configuration
RPC=https://your-rpc-endpoint-here
PRIVATE_KEY=your_private_key_here
# Contract address (deploy the Counter contract first)
COUNTER_CONTRACT_ADDRESS=0x...npm run incrementOr directly with ts-node:
npx ts-node increment-counter.tsnpm run build
npm start- Connects to your Counter contract
- Reads the current counter value
- Prepares a predicate request to increment the counter by 1
- Evaluates the policy with Predicate
- If compliant, submits the transaction with predicate signatures
- Waits for confirmation and displays the new counter value
- Node.js >= 16.0.0
- A deployed Counter contract with predicate protection
- Valid Predicate API key
- RPC endpoint access
- Private key with sufficient funds for gas
The script interacts with the setNumberWithPredicate function on the Counter contract, which requires:
newNumber: The new value to set (current + 1)predicateMessage: The predicate signature data containing:- Task ID
- Expiration block number
- Signer addresses
- Signatures
The script encodes the internal setNumber(uint256) function call as required by the predicate validation system.