Sign Solana Transactions

Signing a Solana transaction is identical to how we sign an Ethereum transaction with the exception that we need to pass in the Solana specific RPC URL, chain ID, and method. In the example we are going to update:

  • chainID to solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z

  • rpcUrl to https://api.testnet.solana.com

  • method to sol_signAndConfirmTransaction

  • params to a stringified object Solana transaction

Below is an example curl command for signing a Solana message:

curl -X POST 'https://mpc-client.portalhq.io/v1/sign' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer <clientApiKey>' \
  -d '{
    "share": $share,
    "method": "sol_signAndConfirmTransaction",
    "params": "{\"signatures\":null,\"message\":{\"accountKeys\":[\"4T3H8S4neZifbcNyvuhfemwaMHv2j5Gg3aWr896gbHD5\",\"GPsPXxoQA51aTJJkNHtFDFYui5hN5UxcFPnheJEHa5Du\",\"11111111111111111111111111111111\"],\"header\":{\"numRequiredSignatures\":1,\"numReadonlySignedAccounts\":0,\"numReadonlyUnsignedAccounts\":1},\"recentBlockhash\":\"9U6c2rJsmGaj6VgQxLS6VytoqDKqwTB1eXWWBcdq9AKQ\",\"instructions\":[{\"programIdIndex\":2,\"accounts\":[0,1],\"data\":\"3Bxs49okdgVMmkxX\"}]}}",
    "rpcUrl": "https://api.testnet.solana.com",
    "chainId": "solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z",
    "metadataStr": "{\"clientPlatform\":\"CLI\",\"mpcServerVersion\":\"v6\",\"chainId\":\"solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z\",\"optimized\":true,\"performanceId\":\"\"}"
  }'

Last updated