File tree Expand file tree Collapse file tree 6 files changed +49
-19
lines changed
payment-processor/src/payment
usage-examples/src/hinkal Expand file tree Collapse file tree 6 files changed +49
-19
lines changed Original file line number Diff line number Diff line change @@ -52,7 +52,6 @@ export async function payErc20FeeProxyRequest(
5252 * @param signerOrProvider the Web3 provider, or signer. Defaults to window.ethereum.
5353 * @param amount optionally, the amount to pay. Defaults to remaining amount of the request.
5454 * @param feeAmount optionally, the fee amount to pay. Defaults to the fee amount.
55- * @param overrides optionally, override default transaction values, like gas.
5655 */
5756export async function payPrivateErc20FeeProxyRequest (
5857 request : ClientTypes . IRequestData ,
Original file line number Diff line number Diff line change @@ -3,8 +3,13 @@ import { Signer } from 'ethers';
33import { Hinkal , exportEthersProvider , preProcessing } from '@hinkal/common' ;
44
55/**
6- * prepares wrapper hinkal object for private transaction
7- * @param signer signer object to be passed
6+ * Prepares a wrapper Hinkal object for private transactions.
7+ * This function initializes the necessary components for private transaction processing
8+ * including provider setup, user keys, and Merkle tree initialization.
9+ *
10+ * @param signer - The ethers.js Signer instance for transaction signing
11+ * @returns Promise<Hinkal<unknown>> - A configured Hinkal instance ready for private transactions
12+ * @throw If initialization of provider, user keys, or Merkle tree fails
813 */
914export const prepareHinkal = async ( signer : Signer ) : Promise < Hinkal < unknown > > => {
1015 await preProcessing ( ) ;
@@ -15,6 +20,7 @@ export const prepareHinkal = async (signer: Signer): Promise<Hinkal<unknown>> =>
1520 await hinkal . initProviderAdapter ( undefined , ethersProvider ) ;
1621 await hinkal . initUserKeys ( ) ;
1722
23+ // initialize merkle trees
1824 await hinkal . resetMerkle ( ) ;
1925
2026 return hinkal ;
Original file line number Diff line number Diff line change @@ -6,8 +6,12 @@ export interface IPreparedTransaction {
66 to : string ;
77}
88
9+ /** Interface for preparing private transactions using Hinkal middleware */
910export interface IPreparedPrivateTransaction {
11+ /** Amount to pay in base units (wei or the smallest possible unit of ERC20 token) */
1012 amountToPay : bigint ;
13+ /** ERC20 token contract address */
1114 tokenAddress : string ;
15+ /** list of operations encoded as HexStrings */
1216 ops : string [ ] ;
1317}
Original file line number Diff line number Diff line change 11import { ethers } from 'ethers' ;
22import { RequestNetwork , Types , Utils } from '@requestnetwork/request-client.js' ;
33import { EthereumPrivateKeySignatureProvider } from '@requestnetwork/epk-signature' ;
4- import { CurrencyTypes } from '@requestnetwork/types' ;
5-
6- // Example Data:
7- const currencyAddress = '0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85' ; // USDC
8- const currencyAmount = ethers . utils . parseUnits ( '0.01' , 6 ) . toBigInt ( ) ;
9- const currentNetwork = 'sepolia' as CurrencyTypes . ChainName ;
10- const currentCurrenyType = Types . RequestLogic . CURRENCY . ERC20 ;
11- const currentGateway = 'https://sepolia.gateway.request.network' ;
12- const payee = '0xA4faFa5523F63EE58aE7b56ad8EB5a344A19F266' ; // some random address
13- const fee = '0' ;
14- const contentData = {
15- reason : 'Hinkal Test' ,
16- dueDate : '2025.06.16' ,
17- } ;
4+ import {
5+ contentData ,
6+ currencyAddress ,
7+ currencyAmount ,
8+ currentCurrenyType ,
9+ currentGateway ,
10+ currentNetwork ,
11+ fee ,
12+ payee ,
13+ } from './hinkalRequestData' ;
1814
15+ /**
16+ * Creates a payment request with the parameters specified in './hinkalRequestData.ts'
17+ * used by testPayErc20FeeProxyRequestHinkal.ts
18+ * @param payerWallet the wallet used by the payer
19+ * @param privateKey the private of the user creating the request
20+ * @returns Newly created request
21+ */
1922export const createRequestForHinkal = async (
2023 payerWallet : ethers . Wallet ,
2124 privateKey : string ,
Original file line number Diff line number Diff line change 1+ import { ethers } from 'ethers' ;
2+ import { Types } from '@requestnetwork/request-client.js' ;
3+ import { CurrencyTypes } from '@requestnetwork/types' ;
4+
5+ export const currencyAddress = '0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85' ; // USDC
6+ export const currencyAmount = ethers . utils . parseUnits ( '0.01' , 6 ) . toBigInt ( ) ;
7+ export const currentNetwork : CurrencyTypes . ChainName = 'optimism' ;
8+ export const currentCurrenyType = Types . RequestLogic . CURRENCY . ERC20 ;
9+ export const currentGateway = 'https://sepolia.gateway.request.network' ;
10+ export const payee = '0xA4faFa5523F63EE58aE7b56ad8EB5a344A19F266' ; // some random address
11+ export const fee = '0' ;
12+ export const contentData = {
13+ reason : 'Hinkal Test' ,
14+ dueDate : '2025.06.16' ,
15+ } ;
Original file line number Diff line number Diff line change @@ -7,11 +7,14 @@ config();
77// Usage Example of Private Transactions using Hinkal on Optimism
88// You will need to pass PAYER_PRIVATE_KEY to .env file in usage_examples root (make sure dotenv is installed)
99// run --> yarn start:hinkal
10+ // IMPORTANT: Ensure your account has sufficient USDC balance before running
11+ // SECURITY: Handle private keys with extreme caution. Never commit .env file
12+ // NOTE: Ensure sufficient ETH for gas fees on Optimism network yarn start:hinkal
1013
1114void ( async ( ) => {
12- const RPC_URL = 'https://mainnet.optimism.io' ;
13- const { PAYER_PRIVATE_KEY } = process . env ;
15+ const { PAYER_PRIVATE_KEY , OPTIMISM_RPC_URL } = process . env ;
1416 if ( ! PAYER_PRIVATE_KEY ) throw new Error ( 'PRIVATE_KEY_MISSING' ) ;
17+ const RPC_URL = OPTIMISM_RPC_URL || 'https://mainnet.optimism.io' ;
1518
1619 // Create Provider and Signer
1720 const provider = new ethers . providers . JsonRpcProvider ( RPC_URL ) ;
You can’t perform that action at this time.
0 commit comments