Junaidb commited on
Commit
17542bf
·
verified ·
1 Parent(s): 2f68e8e

Update components/functions.py

Browse files
Files changed (1) hide show
  1. components/functions.py +20 -11
components/functions.py CHANGED
@@ -16,7 +16,7 @@ from solders.keypair import Keypair
16
  from solders.pubkey import Pubkey
17
  from solders.system_program import transfer, TransferParams
18
  from solders.transaction import Transaction
19
-
20
 
21
 
22
 
@@ -187,20 +187,29 @@ def SolanaPayment(state):
187
 
188
  lamports = int(float(state["amount"]) * 1_000_000_000)
189
 
190
- tx = Transaction().add(
191
- transfer(
192
- TransferParams(
193
- from_pubkey=sender.pubkey(),
194
- to_pubkey=recipient,
195
- lamports=lamports
196
- )
 
 
197
  )
198
  )
199
-
200
- result = client.send_transaction(tx, sender)
 
 
 
 
 
 
 
 
201
 
202
  return {
203
  "tx_hash": result.value
204
  }
205
 
206
-
 
16
  from solders.pubkey import Pubkey
17
  from solders.system_program import transfer, TransferParams
18
  from solders.transaction import Transaction
19
+ from solders.message import Message
20
 
21
 
22
 
 
187
 
188
  lamports = int(float(state["amount"]) * 1_000_000_000)
189
 
190
+ bh_resp = client.get_latest_blockhash()
191
+ blockhash = bh_resp.value.blockhash
192
+
193
+ #Build instruction
194
+ ix = transfer(
195
+ TransferParams(
196
+ from_pubkey=sender.pubkey(),
197
+ to_pubkey=recipient,
198
+ lamports=lamports
199
  )
200
  )
201
+ #Build message
202
+ msg = Message.new_with_blockhash(
203
+ [ix],
204
+ sender.pubkey(),
205
+ blockhash
206
+ )
207
+ #Build & sign transaction
208
+ tx = Transaction([sender], msg, blockhash)
209
+ #Send it
210
+ result = client.send_transaction(tx)
211
 
212
  return {
213
  "tx_hash": result.value
214
  }
215