scallop-io / sui-scallop-sdk

This is the typescript sdk for the scallop lending platform on SUI network
Apache License 2.0
24 stars 7 forks source link

Error: No valid gas coins found for the transaction when trigger deposit() or depositCollateral() #127

Closed binhnguyen2501 closed 1 month ago

binhnguyen2501 commented 2 months ago

@nicetomeetyou1 i got error Error: No valid gas coins found for the transaction when i trigger deposit() or depositCollateral(). Could you please take a look this issue

Screenshot 2024-06-25 at 17 47 27
nicetomeetyou1 commented 2 months ago

@binhnguyen2501 Could you elaborate on the details? For example, please provide your code and specify which network you use to interact with the Scallop SDK. Is it mainnet or testnet?

binhnguyen2501 commented 2 months ago

i use mainnet when interact with the Scallop SDK @nicetomeetyou1

image
fum-is-chum commented 2 months ago

Hi @binhnguyen2501 can you provide the wallet address that is trying to call this function? I've just tested both deposit and depositCollateral, they work just fine

binhnguyen2501 commented 2 months ago

here is my sui wallet address: 0x389878a582bc9c322ece92f55f269660d1996d3f5111ed41738561cbe71aa8ec and the code i interact with the Scallop SDK

image

@fum-is-chum

fum-is-chum commented 2 months ago

Are you using the latest sdk version v0.46.39? @binhnguyen2501

fum-is-chum commented 2 months ago

It seems like the only possible way to reproduce this bug is when the wallet that is used to sign the tx is different from this one 0x389878a582bc9c322ece92f55f269660d1996d3f5111ed41738561cbe71aa8ec Can you share a bit more of the real code that you're working with? We can help you spot the misconfiguration or mistake @binhnguyen2501

binhnguyen2501 commented 2 months ago

base on https://github.com/scallop-io/sui-scallop-sdk maybe I missed adding the wallet address to your Scallop Client SDK unit. I will try again and send you a reply as soon as possible @nicetomeetyou1 @fum-is-chum

binhnguyen2501 commented 2 months ago

Are you using the latest sdk version v0.46.39? @binhnguyen2501

yes i use the lastest sdk version

fum-is-chum commented 2 months ago

Updated my code base on @nicetomeetyou1 but i still got the same issue

image image

It seems like there's another instance scallopClient? Shouldn't it be scallopClientSDK.deposit?

binhnguyen2501 commented 2 months ago

Updated my code base on @nicetomeetyou1 but i still got the same issue image image

It seems like there's another instance scallopClient? Shouldn't it be scallopClientSDK.deposit?

After updated my code base on @nicetomeetyou1 i still got the above issue

image image

can you guys help me pls @fum-is-chum @nicetomeetyou1

nicetomeetyou1 commented 2 months ago

@binhnguyen2501 try like this one

import { Scallop, ScallopBuilder, ScallopClient, ScallopQuery } from "@scallop-io/sui-scallop-sdk";
import { SuiKit } from '@scallop-io/sui-kit';
import dotenv from "dotenv";
dotenv.config();

async function  main() {
  const suiKit = new SuiKit({
    mnemonics: process.env.MNEMONICS,
    networkType: 'mainnet',
  })
  const scallopClient = new ScallopClient({
    networkType: 'mainnet',
  });
  const scallopQuery = new ScallopQuery({
    networkType: 'mainnet',
  })
  const scallopBuilder = new ScallopBuilder({
    networkType: 'mainnet',
    walletAddress: suiKit.currentAddress(),
  });
  await scallopBuilder.init();
  await scallopQuery.init();
  await scallopClient.init();

  const obligationAddress = await scallopQuery.getObligations(suiKit.currentAddress());

  let obligationId = undefined
  if(obligationAddress.length === 0) {
    obligationId = obligationAddress[0].id;
  } 
  const txBlock = await scallopClient.depositCollateral('sui', 1e9, false, obligationId, suiKit.currentAddress());
  const { digest } = await suiKit.signAndSendTxn(txBlock); // You can use signAndExecuteTransactionBlock() from `@mysten/dapp-kit` for frontend.
  console.log('digest', digest);
}

main().catch(console.error);

In the frontend, you will use @mysten/dapp-kit, right? The error occurs because the transaction is executed by the sukit package, but on the frontend, you don’t use this package. Therefore, you need to pass the false value to function depositCollateral. This way, you will receive a TransactionBlock as a return from the depositCollateral function. Once you get the return from the function, you can sign and execute the transaction.

The depositCollateral function will create a new obligation account if the address does not already have one.

binhnguyen2501 commented 2 months ago

@binhnguyen2501 try like this one

import { Scallop, ScallopBuilder, ScallopClient, ScallopQuery } from "@scallop-io/sui-scallop-sdk";
import { SuiKit } from '@scallop-io/sui-kit';
import dotenv from "dotenv";
dotenv.config();

async function  main() {
  const suiKit = new SuiKit({
    mnemonics: process.env.MNEMONICS,
    networkType: 'mainnet',
  })
  const scallopClient = new ScallopClient({
    networkType: 'mainnet',
  });
  const scallopQuery = new ScallopQuery({
    networkType: 'mainnet',
  })
  const scallopBuilder = new ScallopBuilder({
    networkType: 'mainnet',
    walletAddress: suiKit.currentAddress(),
  });
  await scallopBuilder.init();
  await scallopQuery.init();
  await scallopClient.init();

  const obligationAddress = await scallopQuery.getObligations(suiKit.currentAddress());

  let obligationId = undefined
  if(obligationAddress.length === 0) {
    obligationId = obligationAddress[0].id;
  } 
  const txBlock = await scallopClient.depositCollateral('sui', 1e9, false, obligationId, suiKit.currentAddress());
  const { digest } = await suiKit.signAndSendTxn(txBlock); // You can use signAndExecuteTransactionBlock() from `@mysten/dapp-kit` for frontend.
  console.log('digest', digest);
}

main().catch(console.error);

In the frontend, you will use @mysten/dapp-kit, right? The error occurs because the transaction is executed by the sukit package, but on the frontend, you don’t use this package. Therefore, you need to pass the false value to function depositCollateral. This way, you will receive a TransactionBlock as a return from the depositCollateral function. Once you get the return from the function, you can sign and execute the transaction.

The depositCollateral function will create a new obligation account if the address does not already have one.

I think there were some mistakes when checking the if(obligationAddress.length === 0) condition (the condition should obligationAddress.length !== 0) however everything worked perfectly, thank you so much for your support @nicetomeetyou1 @fum-is-chum @mr-donor . Your team work so hard and great <3

binhnguyen2501 commented 2 months ago

If during the processing process the RPC fails, will our SDK automatically retry sir @nicetomeetyou1 @fum-is-chum

nicetomeetyou1 commented 2 months ago

@binhnguyen2501 There's no auto retry when there's a problem with RPC.