Skip to content

Commit

Permalink
Added readme for using gasEstimator
Browse files Browse the repository at this point in the history
  • Loading branch information
cdc-Hitesh committed Oct 15, 2021
1 parent c2e6c8d commit 5903489
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,32 @@ const msgFundCommPool = cro.v2.distribution.MsgFundCommunityPoolV2.fromCosmosMsg

```

### 1.9. Using the gas estimator for a transaction
You can estimate gas for your transaction before signing and broadcasting it to the network.
Eg.
```typescript
//... initialising

const coin = new cro.Coin('99999999', Units.BASE);

const msgSendV2 = new cro.v2.bank.MsgSendV2({
fromAddress: 'tcro165tzcrh2yl83g8qeqxueg2g5gzgu57y3fe3kc3',
toAddress: 'tcro184lta2lsyu47vwyp2e8zmtca3k5yq85p6c4vp3',
amount: [coin],
});

const rawTxV2 = new cro.v2.RawTransactionV2();
rawTxV2.addMessage(msgSendV2);

const unsignedCosmosTx = rawTxV2.toCosmosJSON();
const estimatedGas = await cro.CroClient.estimateGasLimit(unsignedCosmosTx);

// set `gas_used` to the rawTx
rawTxV2.setGasLimit(estimatedGas.gas_used);

//... Do rest operations

```
## 2. Introducing `V2` message types
Our SDK has introduced `V2` message types in order to support:
- Custom `denom`
Expand Down
6 changes: 3 additions & 3 deletions lib/src/client/client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,10 @@ describe('CroClient', function () {

nock(rpcUrl).persist(true).post('/cosmos/tx/v1beta1/simulate').reply(200, mockSimulatedResponse);

const croHttpClient = await cro.CroClient.estimateGasLimit(cosmosTxObject);
const estimatedGas = await cro.CroClient.estimateGasLimit(cosmosTxObject);

expect(croHttpClient.gas_used).to.be.equal('462867');
expect(croHttpClient.gas_wanted).to.be.equal('0');
expect(estimatedGas.gas_used).to.be.equal('462867');
expect(estimatedGas.gas_wanted).to.be.equal('0');

nock.cleanAll();
});
Expand Down

0 comments on commit 5903489

Please sign in to comment.