[BUG] How to reuse the instance of PrimeSdk in another function to send an transaction
Closed this issue · 6 comments
Describe the bug
[BUG] When we create an instance of PrimeSdk and create an SCW with await primeSdk.getCounterFactualAddress(), how to reuse the instance of PrimeSdk in another function to send an transaction
Expected behavior
Reuse the instance of PrimeSdk in another function to send an transaction
Steps to reproduce
No response
Additional context
No response
Operating system
Linux
Prime SDK version or commit hash
latest
When we create an instance of PrimeSdk and create an SCW with await primeSdk.getCounterFactualAddress(), how to reuse the instance of PrimeSdk in another function to send an transaction
The PrimeSDK instance can be declared globally and reused, no? I do not understand the issue. Please elaborate.
I have this function which create a SCW on the server side (express api) for an user and returns the SCW address.
static async createSmartContractWallet(options: {
chainId: number,
eoaPrivateKey: string,
}) {
const primeSdk = new PrimeSdk({ privateKey: options.eoaPrivateKey }, { chainId: options.chainId, projectKey: '' })
const address: string = await primeSdk.getCounterFactualAddress();
return address
}
then I display the SCW address to the user so that he can send tokens (USDT, USDC or other ERC20 tokens) to the SCW address (wich is deployed on first transaction as I read on the website documentation).
then on another page of my website, a withdrawal request must be sent to server side api, on the server side, I would like to execute a function which will then be responsible for withdrawing the tokens transferred on the SCW to an EOA address.
So my question is: in the withdrawal function I still need to instantiate PrimeSdk()? I think that instantiating PrimeSdk() again will create a new SCW, while I would like to simply reuse the same SCW to be able to transfer the tokens from this SCW to the EOA address provided by the user
I have this function which create a SCW on the server side (express api) for an user and returns the SCW address.
static async createSmartContractWallet(options: { chainId: number, eoaPrivateKey: string, }) { const primeSdk = new PrimeSdk({ privateKey: options.eoaPrivateKey }, { chainId: options.chainId, projectKey: '' })
const address: string = await primeSdk.getCounterFactualAddress(); return address }
then I display the SCW address to the user so that he can send tokens (USDT, USDC or other ERC20 tokens) to the SCW address (wich is deployed on first transaction as I read on the website documentation).
Then on another page I would like to call a function which will then be responsible for withdraw the tokens transferred on the SCW to an EOA address
So my question is, in the retire function, I still need to instantiate PrimeSdk()? I think that instantiating PrimeSdk() again will create a new SCW, while I reuse the same SCW to be able to remove the tokens from this SCW
This isn't an issue with the SDK, but more to do with how you've written your program. I would declare the primeSDK as a global variable, initialise it and store it as a global variable.
The request for creating a SCW and withdrawing the token from this SCW does not occur in a single request, the request for withdrawal can be sent after several days.
The request for creating a SCW and withdrawing the token from this SCW does not occur in a single request, the request for withdrawal can be sent after several days.
Yes, but this is necessarily not an issue with the SDK. It is more to do with your software's architecture. So I am afraid this issue will be closed.
Well I did some tests and I have the solution to my problem.
In fact, you just need to give the private key of the EOS wallet as a parameter to new PrimeSdk() and it returns the same instance for the same SCW that allowed you to obtain the SCW address with: wait primeSdk. getCounterFactualAddress();