@@ -1079,6 +1079,7 @@ def __init__(
1079
1079
ss58_format = self .ss58_format , implements_scale_info = True
1080
1080
)
1081
1081
self .__metadata_cache = {}
1082
+ self ._nonces = {}
1082
1083
self .metadata_version_hex = "0x0f000000" # v15
1083
1084
self .event_loop = event_loop or asyncio .get_event_loop ()
1084
1085
self .sync_calls = sync_calls
@@ -3166,7 +3167,7 @@ async def create_signed_extrinsic(
3166
3167
3167
3168
# Retrieve nonce
3168
3169
if nonce is None :
3169
- nonce = await self .get_account_nonce (keypair .ss58_address ) or 0
3170
+ nonce = await self .get_account_next_index (keypair .ss58_address ) or 0
3170
3171
3171
3172
# Process era
3172
3173
if era is None :
@@ -3358,8 +3359,13 @@ async def get_account_next_index(self, account_address: str) -> int:
3358
3359
# Unlikely to happen, this is a common RPC method
3359
3360
raise Exception ("account_nextIndex not supported" )
3360
3361
3361
- nonce_obj = await self .rpc_request ("account_nextIndex" , [account_address ])
3362
- return nonce_obj ["result" ]
3362
+ async with self ._lock :
3363
+ if self ._nonces .get (account_address ) is None :
3364
+ nonce_obj = await self .rpc_request ("account_nextIndex" , [account_address ])
3365
+ self ._nonces [account_address ] = nonce_obj ["result" ]
3366
+ else :
3367
+ self ._nonces [account_address ] += 1
3368
+ return self ._nonces [account_address ]
3363
3369
3364
3370
async def get_metadata_constant (self , module_name , constant_name , block_hash = None ):
3365
3371
"""
0 commit comments