Hello,
Could you tell me, please, how can I get an answer about the status of the transfer?
Do you have something like a callback, how does it work in card acquiring?
The task is simple: it is necessary to implement the transfer of tokens from one wallet to another. But have a problem with obtaining the transfer status, so that on our side we could assign a successful / unsuccessful status to this transfer.
Why complicate your life with callbacks ))
You may use promises (async/await) to handle translation status easily
try {
transfer (await)
} catch (error) {
throw new Error(error.message);
//unsuccessful
} finally {
immediately update state after transfer
// successful
}
If you don’t quite understand how it works, I can provide more detailed code.
Cheers)
Let’s imagine that we have an asynchronous function for interacting with a contract (buying a product for example) :
const purchase = async (itemId, priceInWei) => {
try {
return await contract.methods
.purchase(itemId)
.send({ from: account.account, value: priceInWei });
} catch (error) {
throw new Error(error.message);
} finally {
// change state immediately after any tx
}
};
This function is a promise, so it can be in 3 states:
pending: initial state, neither fulfilled nor rejected. fulfilled: meaning that the operation was completed successfully. rejected: meaning that the operation failed .
Thanks to these states, you can broadcast transaction status changes directly to the UI.
Hello,
I apologize for such a primitive question, but I can not find an answer to it.
How to make a transfer not in the main network currency: BNB (BEP-20), ETH (Ethereum) but in any other? For example, how to transfer BUSD currency?
Let me describe the case a bit:
It will be something like a payment page, where the user will have to pay with a certain currency, for example, busd.
Payment will not be made through a smart contract, but simply as a transfer from one wallet to another.
How to make a transfer from one wallet to another in the main currencies of the network - I figured it out, but I can’t find how to send other tokens anywhere.
For a better understanding of how tokens ‘work’ under the hood, you should familiarize yourself with the ERC-20 standard. The open source library openZeppelin is perfect for this.
You need to interact with the smart contract of the token you want to transfer to another address.
We are making an interface so that users can pay for goods/services using MetaMask, but payment will be made by direct transfer of tokens to the seller’s wallet.
Hello!
Could you help with such a question?
How to implement the ability to connect a wallet and other actions depending on the network ID?
For example, if the network ID is 56, then start connecting the wallet / transfer, etc., and if not, then give an error.
I am using this example web3.eth.getChainId().then(console.log);
61
but I don’t understand how to apply the result to this or that rule(
Next, you must pass the value set in setApi to the entire application (memoize this to improve performance!), For example, through the context or a convenient state manager for you.