solana-py: Unable to properly sign a transaction to MagicEden

Hello, in order to buy something on MagicEden, I’m using an endpoint called buy_now that sends me back a payload with the following format :

with [‘tx’][‘data’] the message and [‘txSigned’][‘data’] a partially signed transaction. I’m trying to sign the message and to insert it in the first slot of signatures[] of the transaction.

Payload in entry :

{'tx': {'type': 'Buffer', 'data': [2, 1, 9, 21, 196, 1, 121, 246, 8, 50, 175, 233, 165, 26, 58, 31, 47, 169, 127, 105, 114, 246, 195, 127, 107, 150, 107, 81, 27, 242, 42, 139, 211, 125, 28, 252, 5, 127, 54, 85, 153, 40, 206, 27, 171, 173, 182, 91, 139, 93, 158, 49, 186, 39, 248, 83, 155, 236, 96, 44, 203, 26, 220, 42, 251, 159, 70, 112, 234, 229, 246, 49, 247, 171, 199, 192, 75, 0, 164, 243, 164, 173, 173, 204, 108, 103, 77, 32, 29, 248, 152, 212, 87, 233, 255, 150, 147, 163, 18, 20, 46, 102, 223, 57, 126, 136, 59, 186, 161, 206, 130, 78, 143, 99, 68, 124, 54, 187, 28, 214, 169, 184, 137, 146, 121, 188, 11, 38, 234, 75, 163, 227, 159, 245, 230, 90, 36, 4, 85, 130, 248, 34, 4, 215, 246, 88, 214, 129, 157, 51, 165, 199, 101, 224, 234, 73, 209, 32, 159, 190, 135, 97, 212, 111, 105, 68, 93, 31, 113, 62, 39, 206, 222, 140, 109, 115, 71, 173, 36, 186, 212, 191, 186, 139, 47, 118, 15, 86, 147, 62, 225, 155, 19, 124, 188, 32, 130, 24, 74, 93, 25, 73, 136, 231, 60, 239, 217, 165, 75, 201, 251, 81, 250, 184, 172, 180, 74, 170, 178, 26, 93, 235, 115, 244, 5, 241, 178, 37, 12, 158, 58, 228, 224, 183, 152, 74, 250, 18, 157, 96, 7, 160, 158, 224, 142, 150, 46, 161, 202, 218, 73, 218, 230, 18, 50, 147, 194, 191, 195, 125, 8, 175, 246, 228, 16, 89, 36, 102, 175, 155, 72, 107, 229, 118, 121, 242, 246, 139, 65, 205, 220, 49, 224, 32, 146, 119, 74, 143, 99, 98, 237, 19, 164, 241, 157, 127, 75, 73, 147, 5, 131, 61, 229, 232, 186, 71, 117, 202, 167, 81, 61, 69, 95, 107, 207, 2, 115, 207, 210, 53, 247, 102, 81, 2, 23, 197, 60, 244, 161, 168, 23, 23, 33, 75, 127, 220, 222, 157, 73, 117, 58, 207, 101, 174, 28, 121, 154, 190, 255, 161, 186, 205, 218, 172, 143, 144, 113, 213, 119, 12, 213, 213, 20, 42, 184, 68, 163, 179, 252, 28, 238, 92, 2, 7, 247, 226, 10, 211, 129, 107, 192, 1, 198, 251, 136, 30, 2, 103, 195, 27, 24, 204, 62, 20, 138, 10, 82, 147, 129, 137, 32, 237, 250, 237, 171, 57, 30, 73, 51, 108, 11, 116, 219, 102, 157, 16, 71, 3, 66, 75, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 26, 136, 115, 139, 250, 198, 10, 13, 26, 130, 255, 192, 253, 225, 104, 17, 209, 176, 195, 48, 48, 68, 144, 55, 86, 179, 38, 200, 206, 101, 253, 239, 8, 209, 122, 249, 173, 94, 22, 105, 150, 178, 108, 233, 210, 121, 80, 93, 128, 143, 222, 100, 131, 254, 248, 217, 106, 235, 99, 8, 128, 8, 203, 113, 6, 221, 246, 225, 215, 101, 161, 147, 217, 203, 225, 70, 206, 235, 121, 172, 28, 180, 133, 237, 95, 91, 55, 145, 58, 140, 245, 133, 126, 255, 0, 169, 6, 167, 213, 23, 25, 44, 92, 81, 33, 140, 201, 76, 61, 74, 241, 127, 88, 218, 238, 8, 155, 161, 253, 68, 227, 219, 217, 138, 0, 0, 0, 0, 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, 219, 233, 248, 89, 0, 11, 227, 225, 235, 161, 122, 71, 63, 137, 176, 247, 232, 226, 73, 64, 242, 10, 235, 142, 188, 167, 26, 136, 253, 233, 93, 75, 131, 183, 26, 9, 5, 33, 159, 137, 154, 129, 212, 255, 132, 251, 89, 61, 46, 223, 138, 144, 172, 27, 58, 179, 66, 88, 247, 223, 35, 62, 165, 3, 2, 177, 189, 46, 205, 33, 64, 224, 186, 130, 65, 227, 93, 10, 193, 134, 47, 123, 19, 30, 70, 242, 146, 250, 186, 131, 119, 230, 223, 15, 6, 200, 52, 135, 241, 92, 3, 20, 6, 0, 1, 2, 8, 12, 13, 17, 242, 35, 198, 137, 82, 225, 242, 182, 255, 0, 23, 100, 7, 0, 0, 0, 0, 20, 12, 0, 1, 14, 15, 2, 8, 12, 3, 8, 16, 13, 17, 34, 102, 6, 61, 18, 1, 218, 235, 234, 255, 255, 0, 23, 100, 7, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 20, 22, 0, 4, 1, 5, 14, 15, 2, 6, 8, 12, 7, 3, 8, 9, 8, 16, 13, 18, 19, 17, 10, 11, 42, 37, 74, 217, 157, 79, 49, 35, 6, 255, 250, 0, 23, 100, 7, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255]}, 'txSigned': {'type': 'Buffer', 'data': [2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 236, 72, 248, 210, 27, 195, 225, 195, 236, 128, 200, 183, 128, 195, 174, 10, 166, 181, 191, 241, 121, 21, 87, 232, 145, 169, 146, 168, 241, 1, 66, 204, 164, 143, 99, 121, 7, 163, 201, 176, 220, 191, 220, 99, 140, 228, 151, 111, 113, 138, 82, 86, 148, 253, 143, 194, 250, 145, 241, 152, 57, 242, 0, 2, 1, 9, 21, 196, 1, 121, 246, 8, 50, 175, 233, 165, 26, 58, 31, 47, 169, 127, 105, 114, 246, 195, 127, 107, 150, 107, 81, 27, 242, 42, 139, 211, 125, 28, 252, 5, 127, 54, 85, 153, 40, 206, 27, 171, 173, 182, 91, 139, 93, 158, 49, 186, 39, 248, 83, 155, 236, 96, 44, 203, 26, 220, 42, 251, 159, 70, 112, 234, 229, 246, 49, 247, 171, 199, 192, 75, 0, 164, 243, 164, 173, 173, 204, 108, 103, 77, 32, 29, 248, 152, 212, 87, 233, 255, 150, 147, 163, 18, 20, 8, 175, 246, 228, 16, 89, 36, 102, 175, 155, 72, 107, 229, 118, 121, 242, 246, 139, 65, 205, 220, 49, 224, 32, 146, 119, 74, 143, 99, 98, 237, 19, 46, 102, 223, 57, 126, 136, 59, 186, 161, 206, 130, 78, 143, 99, 68, 124, 54, 187, 28, 214, 169, 184, 137, 146, 121, 188, 11, 38, 234, 75, 163, 227, 159, 245, 230, 90, 36, 4, 85, 130, 248, 34, 4, 215, 246, 88, 214, 129, 157, 51, 165, 199, 101, 224, 234, 73, 209, 32, 159, 190, 135, 97, 212, 111, 105, 68, 93, 31, 113, 62, 39, 206, 222, 140, 109, 115, 71, 173, 36, 186, 212, 191, 186, 139, 47, 118, 15, 86, 147, 62, 225, 155, 19, 124, 188, 32, 130, 24, 74, 93, 25, 73, 136, 231, 60, 239, 217, 165, 75, 201, 251, 81, 250, 184, 172, 180, 74, 170, 178, 26, 93, 235, 115, 244, 5, 241, 178, 37, 12, 158, 58, 228, 224, 183, 152, 74, 250, 18, 157, 96, 7, 160, 158, 224, 142, 150, 46, 161, 202, 218, 73, 218, 230, 18, 50, 147, 194, 191, 195, 125, 164, 241, 157, 127, 75, 73, 147, 5, 131, 61, 229, 232, 186, 71, 117, 202, 167, 81, 61, 69, 95, 107, 207, 2, 115, 207, 210, 53, 247, 102, 81, 2, 23, 197, 60, 244, 161, 168, 23, 23, 33, 75, 127, 220, 222, 157, 73, 117, 58, 207, 101, 174, 28, 121, 154, 190, 255, 161, 186, 205, 218, 172, 143, 144, 113, 213, 119, 12, 213, 213, 20, 42, 184, 68, 163, 179, 252, 28, 238, 92, 2, 7, 247, 226, 10, 211, 129, 107, 192, 1, 198, 251, 136, 30, 2, 103, 195, 27, 24, 204, 62, 20, 138, 10, 82, 147, 129, 137, 32, 237, 250, 237, 171, 57, 30, 73, 51, 108, 11, 116, 219, 102, 157, 16, 71, 3, 66, 75, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 26, 136, 115, 139, 250, 198, 10, 13, 26, 130, 255, 192, 253, 225, 104, 17, 209, 176, 195, 48, 48, 68, 144, 55, 86, 179, 38, 200, 206, 101, 253, 239, 8, 209, 122, 249, 173, 94, 22, 105, 150, 178, 108, 233, 210, 121, 80, 93, 128, 143, 222, 100, 131, 254, 248, 217, 106, 235, 99, 8, 128, 8, 203, 113, 6, 221, 246, 225, 215, 101, 161, 147, 217, 203, 225, 70, 206, 235, 121, 172, 28, 180, 133, 237, 95, 91, 55, 145, 58, 140, 245, 133, 126, 255, 0, 169, 6, 167, 213, 23, 25, 44, 92, 81, 33, 140, 201, 76, 61, 74, 241, 127, 88, 218, 238, 8, 155, 161, 253, 68, 227, 219, 217, 138, 0, 0, 0, 0, 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, 219, 233, 248, 89, 0, 11, 227, 225, 235, 161, 122, 71, 63, 137, 176, 247, 232, 226, 73, 64, 242, 10, 235, 142, 188, 167, 26, 136, 253, 233, 93, 75, 131, 183, 26, 9, 5, 33, 159, 137, 154, 129, 212, 255, 132, 251, 89, 61, 46, 223, 138, 144, 172, 27, 58, 179, 66, 88, 247, 223, 35, 62, 165, 3, 2, 177, 189, 46, 205, 33, 64, 224, 186, 130, 65, 227, 93, 10, 193, 134, 47, 123, 19, 30, 70, 242, 146, 250, 186, 131, 119, 230, 223, 15, 6, 200, 52, 135, 241, 92, 3, 20, 6, 0, 1, 2, 3, 12, 13, 17, 242, 35, 198, 137, 82, 225, 242, 182, 255, 0, 23, 100, 7, 0, 0, 0, 0, 20, 12, 0, 1, 14, 15, 2, 3, 12, 4, 3, 16, 13, 17, 34, 102, 6, 61, 18, 1, 218, 235, 234, 255, 255, 0, 23, 100, 7, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 20, 22, 0, 5, 1, 6, 14, 15, 2, 7, 3, 12, 8, 4, 3, 9, 3, 16, 13, 18, 19, 17, 10, 11, 42, 37, 74, 217, 157, 79, 49, 35, 6, 255, 250, 0, 23, 100, 7, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255]}}

and here is my code :

  txSigned = tx_data['txSigned']['data']
  tx = bytes(tx_data['tx']['data'])
  client = AsyncClient("https://api.mainnet-beta.solana.com")
  payer = Keypair.from_secret_key(b58decode(mypkey))
  sig = payer.sign(tx)
  tra = Transaction.deserialize(bytes(txSigned))
  tra.signatures[0].signature = sig.signature
  
  tra = Transaction.serialize(tra)
  txn = await client.send_raw_transaction(tra)

I keep encountering : ‘transaction has not been signed correctly’

is this a bug? thanks a lot

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Comments: 32 (8 by maintainers)

Most upvoted comments

Hey @0xTechnician txSigned is a partially signed transaction, I’m not sure what the equivalent in Python is, but here is my JavaScript code that works: image Does it make sense? You shouldn’t be unpacking the transaction or using tx at all, only sign txSigned (which is partial signed already), and then send the transaction Maybe something like this would work? (again I dont know the python equivalents to the web3 lib soz)

txSigned = tx_data['txSigned']['data']
client = AsyncClient("https://api.mainnet-beta.solana.com")
payer = Keypair.from_secret_key(b58decode(mypkey))
payer.sign(txSigned)
tra = Transaction.serialize(tra)
txn = await client.send_raw_transaction(tra)

did this work for you? @0xTechnician

No it didnt

I succeeded after a lot of effort I can share in exchange for 3 sol socialmm#4049

the transaction is a whole mess mate. I’m sorry but it will take more than a few hours for me to actually provide a solution.

the good news is that it can be done. good luck.

do note that before the buy_now you will have to deposit the buy price into escrow.

‘bytes’ object has no attribute ‘recent_blockhash’ when sending transaction

try checking if tra.recent_blockhash is there after deserializing. and what version of solana-py are you on?

Now there is something in recent_blockhash (with this solution). “GLau6pmJYokXk6gMD6AGRaY8yKx6p3HpkccL7ux7VniK”

and error is now : {‘code’: -32602, ‘message’: ‘invalid transaction: Transaction failed to sanitize accounts offsets correctly’}

my solana-py version is 0.23.1

thanks again

I believe that is error is due to multi signing. As mentionned above, someone overcame this problem by editing the bytes of the txSigned with the signature of the message

(https://github.com/bmresearch/Solnet/issues/399)

yeah, saw it.

I’ll try to reproduce the txn.

meanwhile please update to latest solana-py and retry.

print the transaction before serializing. it would show you the whole transaction. perhaps you would find the problem from there.