简体   繁体   English

如何在@solana/web3.js 交易中指定最高费用

[英]How to specify max fee in @solana/web3.js Transaction

The Solana documentation says Solana 文档说

Transactions currently include a fee field that indicates the maximum fee field a slot leader is permitted to charge to process a transaction.交易目前包括一个费用字段,该字段指示允许插槽领导者收取以处理交易的最大费用字段。

(source: https://docs.solana.com/implemented-proposals/transaction-fees ) (来源: https ://docs.solana.com/implemented-proposals/transaction-fees)

But in @solana/web3.js , the transaction builder SystemProgram.transfer only takes a from, to and amount.但是在@solana/web3.js中,事务构建器SystemProgram.transfer只需要一个 from、to 和 amount。 There is a fee calculator interface and a getEstimatedFee method in the transfer object, but I can't find how to set the maximum.转账对象中有一个费用计算器接口和一个getEstimatedFee方法,但是我找不到如何设置最大值。

You don't need to specify a fee because as of now there is no eth-like fee market in Solana where people bid to get their tx included.您不需要指定费用,因为到目前为止,在 Solana 中没有类似 eth 的费用市场,人们竞标将他们的 tx 包括在内。 In future, this is subject to change.将来,这可能会发生变化。 To send a transfer transaction:发送转账交易:

const transferTransaction = new Transaction().add(
  SystemProgram.transfer({
    fromPubkey: fromKeypair.publicKey,
    toPubkey: toKeypair.publicKey,
    lamports: lamportsToSend,
  })
);

await sendAndConfirmTransaction(connection, transferTransaction, [fromKeypair]);

https://solanacookbook.com/references/basic-transactions.html#how-to-send-sol https://solanacookbook.com/references/basic-transactions.html#how-to-send-sol

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 Web3.js 通过 Solana Pay 连接虚拟钱包? - How to connect phantom wallet by Solana Pay using Web3.js? Solana/Web3.js:@Solana/web3.js 是否支持 Solana 当前价格? - Solana/Web3.js: Does @Solana/web3.js support the current price for Solana? 如何通过“@solana/web3.js”和“@solana/sol-wallet-adapter”传输自定义 SPL 令牌 - How to transfer custom SPL token by '@solana/web3.js' and '@solana/sol-wallet-adapter' 如何通过“@solana/web3.js”和“@solana/spl-token”调用 nft 程序? - How to make a call to nft programs by '@solana/web3.js' and "@solana/spl-token"? 使用 @solana/web3.js 将元数据添加到 Solana 令牌 - Add Meta Data To Solana Token with @solana/web3.js 如何使用 @solana/web3.js 从 Solana 中的自定义令牌中删除铸币权限? - How do I remove the minting authority from my custom token in Solana using @solana/web3.js? Web3.js - 如何签署一个交换的批准交易? - Web3.js - How to sign an approve transaction for a swap? 使用 phantom @solana/web3.js 在主网上发送自定义令牌 - Send a custom token on mainnet using phantom @solana/web3.js web3.js:估算usdt智能合约转账的gas费用 - web3.js: Estimate gas fee on usdt smart contract transfer 尝试发送 USDC 时无法获得钱包签名者 @solana-labs/web3.js - Can't get wallet signer @solana-labs/web3.js while trying to send USDC
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM