@@ -11,7 +11,7 @@ import { ContractCallResult, ContractRead, MapMessageExec, MapMessageRead } from
1111import BN from 'bn.js' ;
1212import { map } from 'rxjs/operators' ;
1313import ApiBase from '@polkadot/api/base' ;
14- import { assert , isFunction , isUndefined , stringCamelCase } from '@polkadot/util' ;
14+ import { assert , bnToBn , isFunction , isUndefined , stringCamelCase } from '@polkadot/util' ;
1515
1616import Abi from '../Abi' ;
1717import { encodeMessage , formatData } from '../util' ;
@@ -60,8 +60,16 @@ export default class Contract<ApiType extends ApiTypes> extends Base<ApiType> {
6060 return this . #tx;
6161 }
6262
63+ #getGas = ( _gasLimit : BigInt | BN | string | number ) : BN => {
64+ const gasLimit = bnToBn ( _gasLimit ) ;
65+
66+ return gasLimit . lten ( 0 )
67+ ? this . api . consts . system . maximumBlockWeight . muln ( 64 ) . divn ( 100 )
68+ : gasLimit ;
69+ }
70+
6371 #exec = ( messageOrId : AbiMessage | string | number , value : BigInt | BN | string | number , gasLimit : BigInt | BN | string | number , params : CodecArg [ ] ) : SubmittableExtrinsic < ApiType > => {
64- return this . api . tx . contracts . call ( this . address , value , gasLimit , encodeMessage ( this . registry , this . abi . findMessage ( messageOrId ) , params ) ) ;
72+ return this . api . tx . contracts . call ( this . address , value , this . #getGas ( gasLimit ) , encodeMessage ( this . registry , this . abi . findMessage ( messageOrId ) , params ) ) ;
6573 }
6674
6775 #read = ( messageOrId : AbiMessage | string | number , value : BigInt | BN | string | number , gasLimit : BigInt | BN | string | number , params : CodecArg [ ] ) : ContractRead < ApiType > => {
@@ -74,7 +82,7 @@ export default class Contract<ApiType extends ApiTypes> extends Base<ApiType> {
7482 send : this . _decorateMethod ( ( origin : string | AccountId | Uint8Array ) : ContractCallResult < 'rpc' > =>
7583 this . api . rx . rpc . contracts . call ( {
7684 dest : this . address ,
77- gasLimit,
85+ gasLimit : this . #getGas ( gasLimit ) ,
7886 inputData : encodeMessage ( this . registry , message , params ) ,
7987 origin,
8088 value
0 commit comments