跳到主要内容

转账

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。

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}`);