2

I am using an API that builds a TX for me. I get the following fields:

{
        "encoded_transaction": "AgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJ8BoG0TEegS906MGbDgXPSg+HgRFoawgmQFOsZKymk3F3qa9Rnm1tRSsZ7FEeL1sXHdOfFEqa7conGFok4pEGAgAEB1ZGrTstMXNejpBNpRuoILK/CoHDoAORkS0dtKy/8nDVY0uB7d9dr/9IL0Hbj4GcII0mOr2j8RMXG5aCIiSbEIS/yERcQx4jhiIYxMpHsF7gX8p7kLSvZ9WogMJR7/523wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAC3BlsePRfEU4nVJ/awTDzVi4bHMaoP21SbbRvAP4KUYGp9UXGSxcUSGMyUw9SvF/WNruCJuh/UTj29mKAAAAAAbd9uHXZaGT2cvhRs7reawctIXtX1s3kTqM9YV+/wCpsLRonz/c+tBFZZgTyWaIm0foAn+53qw5dXtNhmM6oS8DAwIAATQAAAAAYE0WAAAAAABSAAAAAAAAAAbd9uHXZaGT2cvhRs7reawctIXtX1s3kTqM9YV+/wCpBgIBBUMAAFZGrTstMXNejpBNpRuoILK/CoHDoAORkS0dtKy/8nDVAVZGrTstMXNejpBNpRuoILK/CoHDoAORkS0dtKy/8nDVBAYCAQAAAAOZASEEAAAAU2hpdAMAAABTSFRYAAAAaHR0cHM6Ly9uZnRzdG9yYWdlLmxpbmsvaXBmcy9iYWZrcmVpZGJ5cmN6NWdreDZ4aGMzaHJ0ZmlodWI2enAzaWh1ZTRxdnE1Znhub2QyY21jZnRrNXhhaQAAAQEAAABWRq07LTFzXo6QTaUbqCCyvwqBw6ADkZEtHbSsv/Jw1QFkAAABAA==",
        "mint": "7gc9CRNqQF8v8Fo6r5mdFw26W2vaqdTUdWdXhi72rnBu",
        "signers": [
            "6onZzXdurac4ykUCqLewQLDPwfmgHRU9Cu9k6A6anPtx",
            "6onZzXdurac4ykUCqLewQLDPwfmgHRU9Cu9k6A6anPtx"
        ]
    }

Using my private key, how can I sign that and broadcast the tx, using Python?

1
  • Sidenote: that transaction appears to require two signers, and one of them isn't listed in the code sample you've provided: t.ly/_SzvT Jan 23 at 22:42

1 Answer 1

2

You'll need to decode the transaction from base64 into bytes, deserialize the partially signed transaction from that, and then sign / send it with your private key.

Assuming you have the response and your private key, you can do:

import solana.transaction as txlib
from base64 import b64decode
from solana.rpc.api import Client

rpc_client = Client('...endpoint here...')
private_key = '... your private key here... ';
response = '... get the response from the server... ';

wire_txn = b64decode(response['encoded_transaction'])
txn = txlib.Transaction.deserialize(wire_txn)
resp = rpc_client.send_transaction(txn, private_key)

Adapated from the tests in https://github.com/michaelhly/solana-py/tree/master

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.