Al366io / solana-transactions-wrapper

Handy tool to execute buy/sell transactions on the SOLANA chain
https://www.npmjs.com/package/solana-transactions-wrapper
MIT License
51 stars 11 forks source link

error buy_token #6

Closed tn-darkcode closed 7 months ago

tn-darkcode commented 7 months ago

i got this error The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received undefined

im passing a config object = { string, string, string, number //0.005, 1 }

Al366io commented 7 months ago

Please refer to the type of config object

type buyConfig = {
    RPC_ENDPOINT: string;
    WALLET_PRIVATE_KEY: string;
    ADDRESS_OF_TOKEN_TO_BUY: string;
    AMOUNT_OF_SOLANA_TO_SPEND: number;
    SLIPPAGE: number;
  }
tn-darkcode commented 7 months ago

i did exactly that object type and i was debugging your package and all the args are typed right

tn-darkcode commented 7 months ago
const buy_token = (config) => __awaiter(void 0, void 0, void 0, function* () {
    const { RPC_ENDPOINT, WALLET_PRIVATE_KEY, ADDRESS_OF_TOKEN_TO_BUY, AMOUNT_OF_SOLANA_TO_SPEND, SLIPPAGE = 1 } = config;
    try {
        const connection = (0, swapper_helper_1.createConnection)(RPC_ENDPOINT);
        console.log("Connection established 🚀");
        const wallet = new anchor_1.Wallet(web3_js_1.Keypair.fromSecretKey(bs58_1.default.decode(WALLET_PRIVATE_KEY)));
        console.log("Wallet fetched ✅");
        console.log(`Trying to buy token using ${AMOUNT_OF_SOLANA_TO_SPEND} SOL...`);
        yield (0, buy_helper_1.buyToken)(ADDRESS_OF_TOKEN_TO_BUY, AMOUNT_OF_SOLANA_TO_SPEND, SLIPPAGE, connection, wallet);
    }
    catch (error) {
        throw new Error(error.message);
    }
});

this function im takling about

Al366io commented 7 months ago

Yeah this is the function I wrote

Can you instead share how you use it? Paste the code in which you create the config object and call this function

Al366io commented 7 months ago

Also The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received undefined who throws this error ? Which line? Which function?

You should include a bit more context or it becomes hard to help 😁

Al366io commented 7 months ago

@tn-darkcode Fixed? Can i close this? :)