@@ -71,7 +71,20 @@ extension web3.BrowserFunctions {
71
71
guard let publicKey = SECP256K1 . recoverPublicKey ( hash: hash, signature: signatureData) else { return nil }
72
72
return Web3 . Utils. publicToAddressString ( publicKey)
73
73
}
74
-
74
+
75
+
76
+ public func sendTransaction( _ transactionJSON: [ String : Any ] , password: String = " web3swift " ) -> [ String : Any ] ? {
77
+ guard let transaction = EthereumTransaction . fromJSON ( transactionJSON) else { return nil }
78
+ guard let options = TransactionOptions . fromJSON ( transactionJSON) else { return nil }
79
+ var transactionOptions = TransactionOptions ( )
80
+ transactionOptions. from = options. from
81
+ transactionOptions. to = options. to
82
+ transactionOptions. value = options. value != nil ? options. value! : BigUInt ( 0 )
83
+ transactionOptions. gasLimit = options. gasLimit != nil ? options. gasLimit! : . automatic
84
+ transactionOptions. gasPrice = options. gasPrice != nil ? options. gasPrice! : . automatic
85
+ return self . sendTransaction ( transaction, transactionOptions: transactionOptions, password: password)
86
+ }
87
+
75
88
public func sendTransaction( _ transaction: EthereumTransaction , transactionOptions: TransactionOptions , password: String = " web3swift " ) -> [ String : Any ] ? {
76
89
do {
77
90
let result = try self . web3. eth. sendTransaction ( transaction, transactionOptions: transactionOptions, password: password)
@@ -80,7 +93,19 @@ extension web3.BrowserFunctions {
80
93
return nil
81
94
}
82
95
}
83
-
96
+
97
+ public func estimateGas( _ transactionJSON: [ String : Any ] ) -> BigUInt ? {
98
+ guard let transaction = EthereumTransaction . fromJSON ( transactionJSON) else { return nil }
99
+ guard let options = TransactionOptions . fromJSON ( transactionJSON) else { return nil }
100
+ var transactionOptions = TransactionOptions ( )
101
+ transactionOptions. from = options. from
102
+ transactionOptions. to = options. to
103
+ transactionOptions. value = options. value != nil ? options. value! : BigUInt ( 0 )
104
+ transactionOptions. gasLimit = . automatic
105
+ transactionOptions. gasPrice = options. gasPrice != nil ? options. gasPrice! : . automatic
106
+ return self . estimateGas ( transaction, transactionOptions: transactionOptions)
107
+ }
108
+
84
109
public func estimateGas( _ transaction: EthereumTransaction , transactionOptions: TransactionOptions ) -> BigUInt ? {
85
110
do {
86
111
let result = try self . web3. eth. estimateGas ( transaction, transactionOptions: transactionOptions)
@@ -89,6 +114,16 @@ extension web3.BrowserFunctions {
89
114
return nil
90
115
}
91
116
}
117
+
118
+ public func prepareTxForApproval( _ transactionJSON: [ String : Any ] ) -> ( transaction: EthereumTransaction ? , options: TransactionOptions ? ) {
119
+ guard let transaction = EthereumTransaction . fromJSON ( transactionJSON) else { return ( nil , nil ) }
120
+ guard let options = TransactionOptions . fromJSON ( transactionJSON) else { return ( nil , nil ) }
121
+ do {
122
+ return try self . prepareTxForApproval ( transaction, options: options)
123
+ } catch {
124
+ return ( nil , nil )
125
+ }
126
+ }
92
127
93
128
public func prepareTxForApproval( _ trans: EthereumTransaction , options opts: TransactionOptions ) throws -> ( transaction: EthereumTransaction ? , options: TransactionOptions ? ) {
94
129
do {
@@ -107,7 +142,24 @@ extension web3.BrowserFunctions {
107
142
return ( nil , nil )
108
143
}
109
144
}
110
-
145
+
146
+ public func signTransaction( _ transactionJSON: [ String : Any ] , password: String = " web3swift " ) -> String ? {
147
+ guard let transaction = EthereumTransaction . fromJSON ( transactionJSON) else { return nil }
148
+ guard let options = TransactionOptions . fromJSON ( transactionJSON) else { return nil }
149
+ var transactionOptions = TransactionOptions ( )
150
+ transactionOptions. from = options. from
151
+ transactionOptions. to = options. to
152
+ transactionOptions. value = options. value != nil ? options. value! : BigUInt ( 0 )
153
+ transactionOptions. gasLimit = options. gasLimit != nil ? options. gasLimit! : . automatic
154
+ transactionOptions. gasPrice = options. gasPrice != nil ? options. gasPrice! : . automatic
155
+ if let nonceString = transactionJSON [ " nonce " ] as? String , let nonce = BigUInt ( nonceString. stripHexPrefix ( ) , radix: 16 ) {
156
+ transactionOptions. nonce = . manual( nonce)
157
+ } else {
158
+ transactionOptions. nonce = . pending
159
+ }
160
+ return self . signTransaction ( transaction, transactionOptions: transactionOptions, password: password)
161
+ }
162
+
111
163
public func signTransaction( _ trans: EthereumTransaction , transactionOptions: TransactionOptions , password: String = " web3swift " ) -> String ? {
112
164
do {
113
165
var transaction = trans
0 commit comments