1- import { type Hex , type UUID , bigIntReplacer , bigIntReviver , createUUID } from "@happy.tech/common"
1+ import { type Hex , type UUID , bigIntReplacer , bigIntReviver , bigIntToZeroPadded , createUUID } from "@happy.tech/common"
22import { context , trace } from "@opentelemetry/api"
33import type { Insertable , Selectable } from "kysely"
44import { type Address , type ContractFunctionArgs , type Hash , encodeFunctionData } from "viem"
@@ -67,6 +67,11 @@ interface TransactionConstructorBaseConfig {
6767 * The address of the contract that will be called
6868 */
6969 address : Address
70+ /**
71+ * The value of the transaction in wei
72+ * Defaults to 0n
73+ */
74+ value ?: bigint
7075 /**
7176 * The deadline of the transaction in seconds (optional)
7277 * This is used to try to cancel the transaction if it is not included in a block after the deadline to save gas
@@ -111,6 +116,8 @@ export class Transaction {
111116
112117 readonly calldata : Hex
113118
119+ readonly value : bigint
120+
114121 readonly deadline : number | undefined
115122
116123 status : TransactionStatus
@@ -158,6 +165,7 @@ export class Transaction {
158165 this . from = config . from
159166 this . chainId = config . chainId
160167 this . address = config . address
168+ this . value = config . value ?? 0n
161169 this . deadline = config . deadline
162170 this . status = config . status ?? TransactionStatus . Pending
163171 this . attempts = config . attempts ?? [ ]
@@ -270,6 +278,7 @@ export class Transaction {
270278 address : this . address ,
271279 functionName : this . functionName ,
272280 contractName : this . contractName ,
281+ value : bigIntToZeroPadded ( this . value ) , // We convert the bigint value to a zero-padded string because 'value' can exceed the numeric limits of Number
273282 calldata : this . calldata ,
274283 args : this . args ? JSON . stringify ( this . args , bigIntReplacer ) : undefined ,
275284 deadline : this . deadline ,
@@ -286,6 +295,7 @@ export class Transaction {
286295 return new Transaction (
287296 {
288297 ...row ,
298+ value : BigInt ( row . value ) ,
289299 args : row . args ? JSON . parse ( row . args , bigIntReviver ) : undefined ,
290300 attempts : JSON . parse ( row . attempts , bigIntReviver ) ,
291301 collectionBlock : row . collectionBlock ? BigInt ( row . collectionBlock ) : undefined ,
0 commit comments