Quantcast
Channel: Recent Questions - Solana Stack Exchange
Viewing all articles
Browse latest Browse all 7994

Signing multiple transfers using the CLI and submitting them in bulk via HTTP RPC

$
0
0

I'm working on a feature in my app where the user will sign two transfers and then broadcast them in one transaction. I'm a little confused in the steps, and just to clarify we are not using the web3 javascript SDK, and instead need to handle this using the Solana CLI and RPC endpoints.

  1. Signing the transactions.

To start, we sign the two transfers:

# Transfer 1solana transfer --sign-only --output json --blockhash 84Dsd5FuDwqF2G89hWAyvK8EArnqXXXXXX --fee-payer .gas-station-keypair XXXXXXXXXXXXXXBGFVomiSuqKpLbjrEFcnS 1=> {"blockhash": "84Dsd5FuDwqF2G89hWAyvK8EArnqxkCGwDUcXfLCFJgU","signers": [ "CfyCCJNEC8HGDoWLBcBfcWCQbrcN6Q8ds6z3nUhMa168=4R92sqE2BrwrypR7fCmR6tDRt4e42rBs64vFtWRoseBQha64G5a2Sz6uMjugUrERapeSEYZTfNGDVCL83PsWkCn7","FHLdZELUCWFyVngLoJoCZhw5QiMm2LeibaLpmiDUAYsp=58LWtzqfgt6qcyAKAe6idTXXU8HCKA69mpnqVbqYEwbBk8njuLCDvwBm8yFw95RjbKjxFLPx4Bhj2ZRuoEgXWnaw"  ]}# Transfer 2solana transfer --sign-only --output json --blockhash 84Dsd5FuDwqF2G89hWAyvK8EArnqXXXXXX --fee-payer .gas-station-keypair YYYYYYYYYYYBGFVomiSuqKpLbjrEFcnS 0.1=> {"blockhash": "84Dsd5FuDwqF2G89hWAyvK8EArnqxkCGwDUcXfLCFJgU","signers": [ "CHCHCHCHCHCHCHHGDoWLBcBfcWCQbrcN6Q8ds6z3nUhMa168=4R92sqE2BrwrypR7fCmR6tDRt4e42rBs64vFtWRoseBQha64G5a2Sz6uMjugUrERapeSEYZTfNGDVCL83PsWkCn7","CHPEPEPEPEPEPw5QiMm2LeibaLpmiDUAYsp=58LWtzqfgt6qcyAKAe6idTXXU8HCKA69mpnqVbqYEwbBk8njuLCDvwBm8yFw95RjbKjxFLPx4Bhj2ZRuoEgXWnaw"  ]}

Now with both transfers signed by all parties, I want to broadcast them both as one transaction.

  1. Broadcasting the Transaction
curl https://api.devnet.solana.com -X POST -H "Content-Type: application/json" -d '  {"jsonrpc": "2.0","id": 1,"method": "sendTransaction","params": [<WHAT_GOES_HERE>    ]  }'

I'm unclear on how to properly format (combine) the previously signed transactions before base64 encoding them.

--------------UPDATE---------------

I'm using this script to combine two serialized messages and then submit them to the RPC sendTransaction endpoint. However, while there are no errors they transfers also never happen.

#!/bin/bash# Replace with your RPC endpointRPC_URL="http://127.0.0.1:8899"# Load your keypairKEYPAIR=~/keypairs/whale1# Receiver's public keys (replace with actual receiver addresses)RECEIVER_PUBKEY_1=$(solana address -k ./rand1) RECEIVER_PUBKEY_2=$(solana address -k ./rand2)echo "Starting balance for receiver 1: $(solana balance $RECEIVER_PUBKEY_1)"echo "Starting balance for receiver 2: $(solana balance $RECEIVER_PUBKEY_2)"echo "Starting balance for sender: $(solana balance $KEYPAIR)"# Amount to send in SOL for each receiverAMOUNT_1="0.1"AMOUNT_2="0.2"# Get the recent blockhashBLOCKHASH=$(solana block | grep 'Recent Blockhash:' | awk '{print $3}')TX_FILE=~/keypairs/solana_multi_tx.json# Create the first transfer instruction and sign itsolana transfer $RECEIVER_PUBKEY_1 $AMOUNT_1 --from $KEYPAIR --blockhash $BLOCKHASH --sign-only --allow-unfunded-recipient --dump-transaction-message --output json > $TX_FILE# Create the second transfer instruction and sign itsolana transfer $RECEIVER_PUBKEY_2 $AMOUNT_2 --from $KEYPAIR --blockhash $BLOCKHASH --sign-only --allow-unfunded-recipient --dump-transaction-message --output json  | jq '.message'> tx2.json# Combine transactions into oneTX_COMBINED=$(jq -s '.[0].message + .[1]' $TX_FILE tx2.json)# Prepare the signed transactionSIGNED_TX=$(echo $TX_COMBINED | base64)SIGNATURE=$(cat $TX_FILE | jq -r '.signers[0]')# Example command to send one of the transactions, as combining them is complex:# Get response from the RPC endpointRESULT=$(curl -s -X POST -H "Content-Type: application/json" \-d '{"jsonrpc": "2.0","id": 1,"method": "sendTransaction","params": ["'$SIGNED_TX'",    {"encoding": "base64" }  ]}' $RPC_URL)sleep 3echo "Ending balance for receiver 1: $(solana balance $RECEIVER_PUBKEY_1)"echo "Ending balance for receiver 2: $(solana balance $RECEIVER_PUBKEY_2)"echo "Ending balance for sender: $(solana balance $KEYPAIR)"

This is still related to my original post, as it's the steps needed to be completed to broadcast 2 or more signed transfers in one request.

Can anyone please help me understand what I'm missing?


Viewing all articles
Browse latest Browse all 7994

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>