This TypeScript project demonstrates how to use CosmJS to set up and execute restricted authz (authorization) grants on the Noble testnet, with specific allow lists controlling where funds can be sent.
# Clone and setup
git clone <repository-url>
cd noble-authz
npm install
# Generate accounts
npm run generate
# Fund accounts from faucet, then run demo
npm run start
- Generate Noble testnet accounts with private keys
- Create restricted authz grants with allow lists - only specified addresses can receive funds
- Execute authorized transactions within the granted permissions
- Automatic denial of unauthorized recipients
- Node.js 16+
- npm or yarn
- Clone the repository:
git clone <repository-url>
cd noble-authz
- Install dependencies:
npm install
- Generate new accounts:
npm run generate
This creates a .env.local
file with three new accounts (granter, grantee, and test recipient).
-
Fund your accounts with testnet USDC:
- Visit https://faucet.testnet.noble.strange.love/
- Copy the addresses from the generation output
- Request testnet tokens for both accounts
-
Check account balances:
npm run check-balance
Once your accounts have testnet USDC:
npm run start
This will:
- Grant the grantee permission to spend up to 1 USDC from the granter's account only to the grantee's address
- Test 1: Successfully send 0.3 USDC from the granter to the grantee (allowed recipient)
- Test 2: Attempt to send to a random third party address - this will fail with "unauthorized"
- Test 3: Attempt to send back to the granter - this will also fail with "unauthorized"
The demo shows both successful and failed transactions to demonstrate how the allow list works.
npm run generate
- Generate new accounts and save to .env.localnpm run start
- Run the restricted authz examplenpm run check-balance
- Check account balancesnpm run build
- Compile TypeScript to JavaScriptnpm run typecheck
- Check TypeScript typesnpm run dev
- Run with file watching
src/
├── noble-authz-example.ts # Main authz example
├── generate-accounts.ts # Account generation script
└── check-balances.ts # Balance checking utility
The .env.local
file contains:
GRANTER_PRIVATE_KEY
- Hex-encoded private key for the granterGRANTEE_PRIVATE_KEY
- Hex-encoded private key for the granteeGRANTER_ADDRESS
- Noble address of the granterGRANTEE_ADDRESS
- Noble address of the granteeNOBLE_RPC
- RPC endpoint for Noble testnet
.env.local
file or share your private keys! The .env.local
file is already covered by .gitignore
.
- Grant with Allow List: The granter creates an authorization that restricts where funds can be sent
- Execute: The grantee can only send funds to addresses in the allow list
- Automatic Denial: Any attempt to send to unauthorized addresses fails immediately
- Expiration: Grants expire quickly (default 5 minutes) for security
- Allow List: Only pre-approved addresses can receive funds
- Spend Limit: Maximum amount that can be spent through the authorization
- Short Expiration: Grants expire in minutes, not days, for better security
- Use Cases:
- Recurring payments to specific vendors
- Child allowances restricted to approved merchants
- Corporate spending controls
- Automated payments with recipient restrictions
- If RPC connection fails, the check-balances script tries multiple endpoints
- Ensure accounts have sufficient USDC for gas fees (transactions cost ~0.25 USDC in fees)
- Check that private keys are 64 character hex strings without '0x' prefix