Skip to main content
9 events
when toggle format what by license comment
Sep 2, 2022 at 20:03 comment added Ademola The reason why getting the balance immediately after the transfer appears to not work is NOT because transfers are not completed immediately. As @OhadDahan already mentioned, you need to call the user_token_account.reload()?` function after a cpi call to fetch the updated state of the token account. Otherwise there won't be a change to user_token_account.balance and it would wrongly seem like the transfer wasn't completed.
Sep 2, 2022 at 19:21 history edited Ohad Dahan CC BY-SA 4.0
added 145 characters in body
Aug 31, 2022 at 20:10 comment added Ohad Dahan solana-labs.github.io/solana-web3.js/… => preBalances/postBalances doesn't have what you need?. In general if a transfer failed you probably abort the transaction. So if you insist on relying on msg! , just print it after the transfer finished. Store value prior, store transfer value, print the diff/sum after.
Aug 31, 2022 at 19:05 vote accept David Choi
Aug 31, 2022 at 19:03 comment added David Choi I'm trying to log token balances so that a backend system can later retrieve the pre transfer and post transfer balances (we would use the web3js connection.getTransaction function's logMessages field). I don't want to just log the transfer on execution because there's always a small chance a transfer could fail. That's why I need to log it upon commit.
Aug 31, 2022 at 18:46 comment added Ohad Dahan What you're trying to do?
Aug 31, 2022 at 18:46 comment added Ohad Dahan Not sure, but if you know how much you're transferring and you get the transfer result. You can manage it yourself.
Aug 31, 2022 at 18:40 comment added David Choi Thank you for your response. So then it is the amount field. Unfortunately it appears that since calls to transfer do not complete immediately getting the balance immediately after the transfer does not work. Is there a way to wait some time within a Solana program or would this not be allowed since it can cause a delay or program completion.
Aug 31, 2022 at 18:33 history answered Ohad Dahan CC BY-SA 4.0