Skip to content

Commit

Permalink
feat: add gas parameter to transaction response (#286)
Browse files Browse the repository at this point in the history
* feat: add `gas` parameter to transaction response

* chore: changesets

* Update src/types/transaction.ts

* Update frog-transaction-response.mdx

---------

Co-authored-by: awkweb <tom@meagher.co>
Co-authored-by: jxom <jakemoxey@gmail.com>
  • Loading branch information
3 people committed Apr 28, 2024
1 parent f841edc commit bfb2f70
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/fair-lions-vanish.md
@@ -0,0 +1,5 @@
---
"frog": patch
---

Added `gas` parameter to transaction response to specify the gas limit. [See more](https://warpcast.com/horsefacts.eth/0xd6390bb3).
50 changes: 47 additions & 3 deletions site/pages/reference/frog-transaction-response.mdx
Expand Up @@ -81,6 +81,28 @@ app.transaction('/send-ether', (c) => {
})
```

### gas (optional)

- **Type:** `BigInt`

Gas limit of the transaction to send.

```tsx twoslash
// @noErrors
import { Frog, parseEther } from 'frog'

export const app = new Frog()

app.transaction('/send-ether', (c) => {
return c.send({
chainId: 'eip155:10',
gas: 100_000n, // [!code focus]
to: '0xd2135CfB216b74109775236E36d4b433F1DF507B',
value: parseEther('1'),
})
})
```

### to

- **Type:** `Address`
Expand All @@ -104,7 +126,7 @@ app.transaction('/send-ether', (c) => {

### value

- **Type:** `Address`
- **Type:** `Bigint`

Value (in wei) to send with the transaction.

Expand Down Expand Up @@ -256,6 +278,28 @@ app.transaction('/mint', (c) => {
})
```

### gas (optional)

- **Type:** `Bigint`

Gas limit of the transaction to send.

```tsx twoslash
// @noErrors
import { Frog, parseEther } from 'frog'

export const app = new Frog()

app.transaction('/send-ether', (c) => {
return c.send({
chainId: 'eip155:10',
gas: 100_000n, // [!code focus]
to: '0xd2135CfB216b74109775236E36d4b433F1DF507B',
value: parseEther('1'),
})
})
```

### args

- **Type:** `unknown`
Expand Down Expand Up @@ -328,7 +372,7 @@ app.transaction('/mint', (c) => {

### value (optional)

- **Type:** `Address`
- **Type:** `Bigint`

Value to send with the transaction.

Expand Down Expand Up @@ -448,4 +492,4 @@ app.transaction('/raw-send', (c) => {
attribution: true, // [!code focus]
})
})
```
```
2 changes: 2 additions & 0 deletions src/types/transaction.ts
Expand Up @@ -55,6 +55,8 @@ export type EthSendTransactionParameters<quantity = string> = {
attribution?: boolean | undefined
/** Transaction calldata. */
data?: Hex | undefined
/** Gas limit for the transaction. */
gas?: quantity | undefined
/** Transaction target address. */
to: Hex
/** Value to send with transaction (in wei). */
Expand Down
3 changes: 2 additions & 1 deletion src/utils/getTransactionContext.ts
Expand Up @@ -107,7 +107,7 @@ export function getTransactionContext<
req,
res(parameters) {
const { attribution, chainId, method, params } = parameters
const { abi, data, to, value } = params
const { abi, data, gas, to, value } = params
const response: TransactionResponse = {
attribution,
chainId,
Expand All @@ -118,6 +118,7 @@ export function getTransactionContext<
to,
},
}
if (gas) response.params.gas = gas.toString()
if (value) response.params.value = value.toString()
return { data: response, format: 'transaction', status: 'success' }
},
Expand Down

0 comments on commit bfb2f70

Please sign in to comment.