# \[GSN\] Is there a method that can compute the total cost to relay a transaction?

**URL:** <https://forum.openzeppelin.com/t/gsn-is-there-a-method-that-can-compute-the-total-cost-to-relay-a-transaction/1718>\
**Category:** Contracts\
**Created:** [November 7, 2019, 5:54am UTC](https://forum.openzeppelin.com/t/gsn-is-there-a-method-that-can-compute-the-total-cost-to-relay-a-transaction/1718 "2019-11-07T05:54:28Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![meh\_blah](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/meh_blah/32/1368_2.png) [@meh\_blah](https://forum.openzeppelin.com/u/meh_blah)\
**Post date:** [November 7, 2019, 5:54am UTC](https://forum.openzeppelin.com/t/gsn-is-there-a-method-that-can-compute-the-total-cost-to-relay-a-transaction/1718/1 "2019-11-07T05:54:28Z")

</div>

Hey,

I am trying to build a custom strategy for my application and I would like to know that given a transaction, is there a method (similar to `estimateGas`) that I can call to estimate how much the transaction will need (including transaction fees/ relayer service fees)?

Thanks!

---

<div class="post-metadata">

**Author:** ![abcoathup](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/abcoathup/32/415_2.png) [@abcoathup](https://forum.openzeppelin.com/u/abcoathup)\
**Post date:** [November 7, 2019, 8:50am UTC](https://forum.openzeppelin.com/t/gsn-is-there-a-method-that-can-compute-the-total-cost-to-relay-a-transaction/1718/2 "2019-11-07T08:50:11Z")

</div>

Hi @meh_blah,

Welcome to the community 👋

If you are building a custom strategy then the [GSN Strategies](https://docs.openzeppelin.com/contracts/2.x/gsn-strategies) documentation is a good place to start (if you haven’t already).

Looking at GSNRecipientERC20Fee the `acceptRelayedCall` function is passed the `maxPossibleCharge`.

> <https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/GSN/GSNRecipientERC20Fee.sol#L53>

`maxPossibleCharge` is calculated in the RelayHub.

> <https://github.com/tabookey/tabookey-gasless/blob/master/contracts/RelayHub.sol#L446>

---

<div class="post-metadata">

**Author:** ![abcoathup](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/abcoathup/32/415_2.png) [@abcoathup](https://forum.openzeppelin.com/u/abcoathup)\
**Post date:** [November 11, 2019, 12:21am UTC](https://forum.openzeppelin.com/t/gsn-is-there-a-method-that-can-compute-the-total-cost-to-relay-a-transaction/1718/3 "2019-11-11T00:21:34Z")

</div>

Hi @meh_blah,

Did the above answer your question?

---

<div class="post-metadata">

**Author:** ![meh\_blah](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/meh_blah/32/1368_2.png) [@meh\_blah](https://forum.openzeppelin.com/u/meh_blah)\
**Post date:** [November 13, 2019, 11:20pm UTC](https://forum.openzeppelin.com/t/gsn-is-there-a-method-that-can-compute-the-total-cost-to-relay-a-transaction/1718/4 "2019-11-13T23:20:20Z")

</div>

Hey @abcoathup,

Really sorry for the delay in getting back to you regarding this one. I think this should help however, I haven’t tried it yet and will confirm once I have.

I have one more question regarding integrating GSN with my smart contracts. If my recipient contract (say `contract ABC is GSNRecipient`) interacts with other contracts, is it already assumed that `ABC` contract pays gas for those calls as well?

Thanks a ton for all your help!

---

<div class="post-metadata">

**Author:** ![abcoathup](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/abcoathup/32/415_2.png) [@abcoathup](https://forum.openzeppelin.com/u/abcoathup)\
**Post date:** [November 13, 2019, 11:39pm UTC](https://forum.openzeppelin.com/t/gsn-is-there-a-method-that-can-compute-the-total-cost-to-relay-a-transaction/1718/5 "2019-11-13T23:39:15Z")

</div>

Hi @meh_blah,

> [@meh\_blah](#):
>
> If my recipient contract (say `contract ABC is GSNRecipient` ) interacts with other contracts, is it already assumed that `ABC` contract pays gas for those calls as well?

Yes. If a contract `ABC` implements `GSNRecipient` then any relayed call that your [GSN Strategy](https://docs.openzeppelin.com/contracts/2.x/gsn-strategies) accepts, includes the gas cost of `ABC` calling other contracts as part of the transaction.

---

<div class="post-metadata">

**Author:** ![abcoathup](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/abcoathup/32/415_2.png) [@abcoathup](https://forum.openzeppelin.com/u/abcoathup)\
**Post date:** [November 14, 2019, 3:06am UTC](https://forum.openzeppelin.com/t/gsn-is-there-a-method-that-can-compute-the-total-cost-to-relay-a-transaction/1718/6 "2019-11-14T03:06:46Z")

</div>

A post was split to a new topic: [Example of using truffle tests to test a GSN recipient contract?](https://forum.openzeppelin.com/t/example-of-using-truffle-tests-to-test-a-gsn-recipient-contract/1752)
