加油站客户端
Aptos Build加油站客户端允许您提交交易由加油站担保.
版本管理
此软件包使用 变化 用于版本管理。 要作出修改:
- 更改代码
- 运行
pnpm changeset在根目录中 - 遵循提示来描述您的更改
- 随您的更改一起提交生成的更改et文件
- 准备释放时,快跑
pnpm version-packages以更新版本 - 运行
pnpm release以发布新版本
安装
pnpm install @aptos-labs/gas-station-client
这个软件包包含了一个加油站管理员API的客户端. 它主要供Aptos Build使用。 这就是为什么我们公布 这到我们的私人注册.
使用量
建议使用
使用加油站客户端的最简单方法是使用TS SDK的插件接口:
const network = Network.MAINNET;
const gasStationClient = new GasStationTransactionSubmitter({
network,
apiKey: "aptoslabs_21edbqbxyPrS_6fu9i83mYmjid4MVs3Z3XmCeATQ8tkSdd",
});
const config = new AptosConfig({
network,
pluginSettings: {
TRANSACTION_SUBMITTER: gasStationClient,
},
});
const aptos = new Aptos(config);
从此您可以像正常一样使用客户端, 它会通过加油站而不是默认的提交者提交交易 :
const transaction = await aptos.transaction.build.simple({
sender: senderAccount.accountAddress,
// IMPORTANT: Must set withFeePayer: true for gas station transactions.
withFeePayer: true,
data: {
function: "0x1::aptos_account::transfer",
functionArguments: [receiverAccount.accountAddress.toString(), 100],
},
});
const response = await aptos.signAndSubmitTransaction({
signer: senderAccount,
transaction,
});
要提供复刻符号或其他插件参数:
const response = await aptos.signAndSubmitTransaction({
signer: senderAccount,
transaction,
pluginParams: {
recaptchaToken: "your-recaptcha-token",
},
});
忽略插件
如果需要,您可以暂时绕过插件进行单一交易:
const response = await aptos.signAndSubmitTransaction({
signer: senderAccount,
transaction,
// Set this to null to ignore the plugin.
transactionSubmitter: null,
});
您也可以完全禁用/ 重新启用这样的插件 :
aptos.setIgnoreTransactionSubmitter(true);
// Transactions will now go through normal submission (not gas station)
aptos.setIgnoreTransactionSubmitter(false);
// Re-enable the plugin
直接使用
如果您愿意, 您可以直接使用客户端 :
const network = Network.MAINNET;
const config = new AptosConfig({network});
const aptos = new Aptos(config);
// Create the client.
const client = new GasStationClient({
network,
apiKey: "aptoslabs_21edbqbxyPrS_6fu9i83mYmjid4MVs3Z3XmCeATQ8tkSdd",
});
// Build the transaction.
const transaction = await aptos.transaction.build.simple({
sender: alice.accountAddress,
// Make sure that this is set to true.
withFeePayer: true,
data: {
function: "0x1::aptos_account::transfer",
functionArguments: [bob.accountAddress.toString(), 100],
},
});
// Sign it and get an authenticator.
const senderAuthenticator = aptos.transaction.sign({ signer: alice, transaction });
// Submit it to the gas station.
const { transactionHash } = await client.signAndSubmitTransaction({
transaction,
senderAuthenticator,
});
// Wait for the transaction to be executed.
const executedTransaction = await aptos.waitForTransaction({
transactionHash,
options: { checkSuccess: true },
});
console.log("Transaction executed successfully", executedTransaction.hash);