I’m using the following script to submit a transaction that updates the funding rate via the Pyth price feed on Aptos Testnet. However, when the script starts, I often receive the following error on the first attempt:
Move abort in 0x7e783b349d3e89cf5931af376ebeadbfab855b3fa239b7ada8f5a92fbea6b387::pyth: 0x80004
Here is the full code:
import { Account, Aptos, AptosConfig, Ed25519PrivateKey, InputEntryFunctionData, Network, PrivateKey, PrivateKeyVariants } from "@aptos-labs/ts-sdk";
import dotenv from "dotenv";
import { MARKET_PRICE_FEEDS } from "../src/perpetuals/constant";
import { AptosPriceServiceConnection } from "@pythnetwork/pyth-aptos-js";
dotenv.config();
const config = new AptosConfig({ network: Network.TESTNET, fullnode: process.env.NODEREAL_TESTNET_URL });
const aptos = new Aptos(config);
const rawPrivateKey = process.env.APTOS_PRIVATEKEY_2 || '';
const prefixedPrivateKey = `ed25519-priv-${rawPrivateKey}`;
const formattedPrivateKey = PrivateKey.formatPrivateKey(
prefixedPrivateKey,
'ed25519' as PrivateKeyVariants
);
const account = Account.fromPrivateKey({
privateKey: new Ed25519PrivateKey(formattedPrivateKey),
});
let lastUpdateHex = "";
async function main(): Promise<void> {
const priceFeedId = MARKET_PRICE_FEEDS[1338];
const TESTNET_HERMES_ENDPOINT = "https://hermes-beta.pyth.network";
const testnetConnection = new AptosPriceServiceConnection(TESTNET_HERMES_ENDPOINT);
const priceFeedUpdateData = await testnetConnection.getPriceFeedsUpdateData([priceFeedId]);
const newUpdateHex = Buffer.from(priceFeedUpdateData[0]).toString("hex");
console.log("newUpdateHex: ", newUpdateHex);
console.log("lastUpdateHex: ", lastUpdateHex);
if (newUpdateHex === lastUpdateHex) {
console.log("No new price update. Skipping transaction.");
return;
}
lastUpdateHex = newUpdateHex;
const payloadResponse = {
function: "0x732f891290449af5e9369866537a51a8e7dc566791aec61a468223ed840b1eb4::perpetual_core::update_funding_rate_external",
functionArguments: [1338, priceFeedUpdateData],
typeArguments: [],
} as InputEntryFunctionData;
const transactionPayload = await aptos.transaction.build.simple({
sender: account.accountAddress,
data: payloadResponse
});
const committedTxn = await aptos.transaction.signAndSubmitTransaction({
transaction: transactionPayload,
signer: account,
});
console.log(`Submitted transaction: ${committedTxn.hash}`);
const response = await aptos.waitForTransaction({
transactionHash: committedTxn.hash,
});
console.log("response", response.success);
}
setInterval(() => {
main().catch(error => {
console.error('An error occurred:', error);
});
}, 2000); // 10000 ms = 10 seconds
When the script starts, I receive the following error:
Move abort in 0x7e783b349d3e89cf5931af376ebeadbfab855b3fa239b7ada8f5a92fbea6b387::pyth: 0x80004
Here’s the full transaction response
transaction: {
version: '6695136723',
hash: '0x968e4fcf2913a2e592019302905c7c17c72db2115402861524534de760f88098',
state_change_hash: '0xd4d0ec0de026b29b0f336dfa4c879f55d1d124223be91a4dfd27c99fef514294',
event_root_hash: '0x9a6b71794212218afcbeb820e6a2c1b6e19f2416f24733291db777f547158444',
state_checkpoint_hash: null,
gas_used: '97',
success: false,
vm_status: 'Move abort in 0x7e783b349d3e89cf5931af376ebeadbfab855b3fa239b7ada8f5a92fbea6b387::pyth: 0x80004',
accumulator_root_hash: '0x7ef6b1e51c6b6156529c6b5871f0ee12c6337b3ae1b521489e4eefdd4c8a32a6',
changes: [ [Object], [Object], [Object] ],
sender: '0x37d5a65c13e855b49f3b8657589ee2de09d9948a5daedf1ca739fb8a6d50558',
sequence_number: '223',
max_gas_amount: '200000',
gas_unit_price: '100',
expiration_timestamp_secs: '1745315165',
payload: {
function: '0x732f891290449af5e9369866537a51a8e7dc566791aec61a468223ed840b1eb4::perpetual_core::update_funding_rate_external',
type_arguments: [],
arguments: [Array],
type: 'entry_function_payload'
},
signature: {
public_key: '0x333d6ec6ff12f79184b83825e25bf547c53f2af5bc441cdbede8f256cfaf1694',
signature: '0x3258f0ab8016e041ff501f0d0b4087c557217572783ef6dfe77138f97f918156480d0511a1aebe7c8b830292fe93bb9318e1a4d7ee1f6de8fde917f69f103c0f',
type: 'ed25519_signature'
},
events: [ [Object] ],
timestamp: '1745315146193550',
type: 'user_transaction'
}
Oddly, the next attempt always succeeds without any issues.
To avoid sending redundant transactions, I added a condition to compare the newly fetched price update data with the last one:
const TESTNET_HERMES_ENDPOINT = "https://hermes-beta.pyth.network";
const testnetConnection = new AptosPriceServiceConnection(TESTNET_HERMES_ENDPOINT);
const priceFeedUpdateData = await testnetConnection.getPriceFeedsUpdateData([priceFeedId]);
I added a condition to check whether the previous and current data are the same data:
if (newUpdateHex === lastUpdateHex)
However, the condition is not being triggered, so it fetches new data every time.
Most of the time, when the script starts, it returns an error on the first attempt, but the subsequent requests succeed. After some time, though, the error occurs again.
This is how we use it and this is where the error occurs:
let coins = coin::withdraw(user, pyth_oracle::get_update_fee(&pyth_update_data));
pyth_oracle::update_price_feeds(pyth_update_data, coins);
let price_id = price_identifier::from_byte_vec(price_data.pyth_price_id);
let price = pyth_oracle::get_price_no_older_than(price_id, PYTH_STALE_PRICE_THRESHOLD);
Could someone please help me identify and resolve this issue?