Wrap SOL
POST https://sol.shrine.trade/api/wrap-sol
Moves SOL into the wallet's wrapped-SOL account, or unwraps by closing that account; unwrapping always returns every lamport in it.
{ "publicKey": "<wallet>", "action": "wrap", "amount": 0.5 }
{ "publicKey": "<wallet>", "action": "unwrap" }
Example
Build, sign, send through the relay. The relay broadcasts through our own Solana endpoint, so the script needs no RPC.
- JavaScript
- Python
import { Keypair, VersionedTransaction } from "@solana/web3.js";
import bs58 from "bs58";
const wallet = Keypair.fromSecretKey(bs58.decode("<your wallet private key, base58>"));
// Half a SOL into wrapped SOL; { action: "unwrap" } brings everything back.
const { tx } = await (await fetch("https://sol.shrine.trade/api/wrap-sol", {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({ publicKey: wallet.publicKey.toBase58(), action: "wrap", amount: 0.5 }),
})).json();
const transaction = VersionedTransaction.deserialize(Buffer.from(tx, "base64"));
transaction.sign([wallet]);
const sent = await (await fetch("https://sol.shrine.trade/api/send", {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({ signedTx: Buffer.from(transaction.serialize()).toString("base64") }),
})).json();
console.log(sent.status, `https://solscan.io/tx/${sent.signature}`);
import base64, requests
from solders.keypair import Keypair
from solders.transaction import VersionedTransaction
wallet = Keypair.from_base58_string("<your wallet private key, base58>")
# Half a SOL into wrapped SOL; {"action": "unwrap"} brings everything back.
r = requests.post("https://sol.shrine.trade/api/wrap-sol",
json={"publicKey": str(wallet.pubkey()), "action": "wrap", "amount": 0.5}).json()
raw = VersionedTransaction.from_bytes(base64.b64decode(r["tx"]))
signed = VersionedTransaction(raw.message, [wallet])
sent = requests.post("https://sol.shrine.trade/api/send",
json={"signedTx": base64.b64encode(bytes(signed)).decode()}).json()
print(sent["status"], sent["explorer"])