1- import { iterativelyCheckStatus , StarknetContract , StringMap } from "./types" ;
2- import { toBN } from "starknet/utils/number" ;
1+ import {
2+ Cairo1ContractClass ,
3+ iterativelyCheckStatus ,
4+ Numeric ,
5+ StarknetContract ,
6+ StringMap
7+ } from "./types" ;
8+ import { toBN , toHex } from "starknet/utils/number" ;
39import * as ellipticCurve from "starknet/utils/ellipticCurve" ;
410import { ec } from "elliptic" ;
511import { HardhatRuntimeEnvironment } from "hardhat/types" ;
@@ -10,7 +16,8 @@ import {
1016 INTERNAL_ARTIFACTS_DIR ,
1117 TransactionHashPrefix ,
1218 TRANSACTION_VERSION ,
13- StarknetChainId
19+ StarknetChainId ,
20+ DECLARE_VERSION
1421} from "./constants" ;
1522import { numericToHexString } from "./utils" ;
1623import * as crypto from "crypto" ;
@@ -187,6 +194,62 @@ export async function sendDeployAccountTx(
187194 } ) ;
188195}
189196
197+ export function calculateDeclareV2TxHash (
198+ accountAddress : string ,
199+ callData : string [ ] ,
200+ maxFee : string ,
201+ chainId : StarknetChainId ,
202+ additionalData : string [ ]
203+ ) {
204+ const calldataHash = hash . computeHashOnElements ( callData ) ;
205+ return hash . computeHashOnElements ( [
206+ TransactionHashPrefix . DECLARE ,
207+ numericToHexString ( DECLARE_VERSION ) ,
208+ accountAddress ,
209+ 0 , // entrypoint selector is implied
210+ calldataHash ,
211+ maxFee ,
212+ chainId ,
213+ ...additionalData
214+ ] ) ;
215+ }
216+
217+ export async function sendDeclareV2Tx (
218+ signatures : string [ ] ,
219+ classHash : string ,
220+ maxFee : Numeric ,
221+ senderAddress : string ,
222+ version : Numeric ,
223+ nonce : Numeric ,
224+ contractClass : Cairo1ContractClass
225+ ) {
226+ const hre = await import ( "hardhat" ) ;
227+ const resp = await axios
228+ . post ( `${ hre . starknet . networkConfig . url } /gateway/add_transaction` , {
229+ type : "DECLARE" ,
230+ contract_class : contractClass . getCompiledClass ( ) ,
231+ signature : signatures ,
232+ sender_address : senderAddress ,
233+ compiled_class_hash : toHex ( toBN ( classHash ) ) ,
234+ version : numericToHexString ( version ) ,
235+ nonce : numericToHexString ( nonce ) ,
236+ max_fee : numericToHexString ( maxFee )
237+ } )
238+ . catch ( ( error : AxiosError ) => {
239+ const msg = `Declaring contract failed: ${ error . response . data . message } ` ;
240+ throw new StarknetPluginError ( msg , error ) ;
241+ } ) ;
242+
243+ return new Promise < string > ( ( resolve , reject ) => {
244+ iterativelyCheckStatus (
245+ resp . data . transaction_hash ,
246+ hre . starknetWrapper ,
247+ ( ) => resolve ( resp . data . transaction_hash ) ,
248+ reject
249+ ) ;
250+ } ) ;
251+ }
252+
190253export async function sendEstimateFeeTx ( data : unknown ) {
191254 const hre = await import ( "hardhat" ) ;
192255 // To resolve TypeError: Do not know how to serialize a BigInt
0 commit comments