转账
POST https://sol.shrine.trade/api/transfer
把 SOL 或任意 SPL 代币发送到另一个钱包。代币转账时,如果收款方的代币账户尚不存在,会自动创建,费用由发送方承担。
{ "publicKey": "<sender>", "to": "<recipient>", "amount": 0.1 }
{ "publicKey": "<sender>", "to": "<recipient>", "mint": "<mint>", "amount": "100%" }
| 字段 | 说明 |
|---|---|
mint | 转 SOL 时省略。 |
amount | 以常规单位表示的 SOL 或代币数量,或余额的百分比:"100%"、"25%"。 |
priorityFee、jitoTip | 可选,单位 SOL。 |
{ "tx": "<base64>", "blockhash": "…", "mint": null, "amount": 0.1, "amountRaw": 100000000, "feeLamports": 0 }
示例
构建、签名、通过中继发送。中继通过我们自己的 Solana 节点广播,所以脚本不需要 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>"));
// 把钱包持有的这个 mint 的全部代币转到另一个钱包。
const { tx } = await (await fetch("https://sol.shrine.trade/api/transfer", {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({ publicKey: wallet.publicKey.toBase58(), to: "<recipient>", mint: "<mint>", amount: "100%" }),
})).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>")
# 把钱包持有的这个 mint 的全部代币转到另一个钱包。
r = requests.post("https://sol.shrine.trade/api/transfer",
json={"publicKey": str(wallet.pubkey()), "to": "<recipient>", "mint": "<mint>", "amount": "100%"}).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"])