File tree Expand file tree Collapse file tree 3 files changed +30
-5
lines changed Expand file tree Collapse file tree 3 files changed +30
-5
lines changed Original file line number Diff line number Diff line change @@ -99,4 +99,21 @@ describe('deploy and test Wallet', () => {
9999
100100 expect ( number . toBN ( res as string ) . toString ( ) ) . toStrictEqual ( number . toBN ( 990 ) . toString ( ) ) ;
101101 } ) ;
102+ test ( 'execute with custom nonce' , async ( ) => {
103+ const { result } = await signer . callContract ( {
104+ contract_address : signer . address ,
105+ entry_point_selector : stark . getSelectorFromName ( 'get_nonce' ) ,
106+ } ) ;
107+ const nonce = parseInt ( result [ 0 ] , 10 ) ;
108+ const { code, transaction_hash } = await signer . addTransaction ( {
109+ type : 'INVOKE_FUNCTION' ,
110+ contract_address : erc20Address ,
111+ entry_point_selector : stark . getSelectorFromName ( 'transfer' ) ,
112+ calldata : [ erc20Address , '10' ] ,
113+ nonce,
114+ } ) ;
115+
116+ expect ( code ) . toBe ( 'TRANSACTION_RECEIVED' ) ;
117+ await defaultProvider . waitForTx ( transaction_hash ) ;
118+ } ) ;
102119} ) ;
Original file line number Diff line number Diff line change @@ -36,11 +36,17 @@ export class Signer extends Provider implements SignerInterface {
3636 "Adding signatures to a signer transaction currently isn't supported"
3737 ) ;
3838
39- const { result } = await this . callContract ( {
40- contract_address : this . address ,
41- entry_point_selector : getSelectorFromName ( 'get_nonce' ) ,
42- } ) ;
43- const nonceBn = toBN ( result [ 0 ] ) ;
39+ let nonceBn ;
40+ if ( transaction . nonce ) {
41+ nonceBn = toBN ( transaction . nonce ) ;
42+ } else {
43+ const { result } = await this . callContract ( {
44+ contract_address : this . address ,
45+ entry_point_selector : getSelectorFromName ( 'get_nonce' ) ,
46+ } ) ;
47+ nonceBn = toBN ( result [ 0 ] ) ;
48+ }
49+
4450 const calldataDecimal = ( transaction . calldata || [ ] ) . map ( ( x ) => toBN ( x ) . toString ( ) ) ;
4551
4652 const msgHash = addHexPrefix (
Original file line number Diff line number Diff line change @@ -51,6 +51,7 @@ export type DeployTransaction = {
5151 contract_definition : CompressedCompiledContract ;
5252 contract_address_salt : BigNumberish ;
5353 constructor_calldata : string [ ] ;
54+ nonce ?: BigNumberish ;
5455} ;
5556
5657export type InvokeFunctionTransaction = {
@@ -60,6 +61,7 @@ export type InvokeFunctionTransaction = {
6061 entry_point_type ?: EntryPointType ;
6162 entry_point_selector : string ;
6263 calldata ?: string [ ] ;
64+ nonce ?: BigNumberish ;
6365} ;
6466
6567export type CallContractTransaction = Omit < InvokeFunctionTransaction , 'type' > ;
You can’t perform that action at this time.
0 commit comments