I want to airdrop and presale my won token
so in the next step I want to lock them until my IDO data come
and unlock in this time 30% of user wallet balances
and next month 50 %
what is the best way to do this
If you want your token to be sent to users when certain date comes automatically without backend or any users or you doing the transactions, it is not possible. Blockchain operations cannot be executed without calling a transaction using scripts by user or backend.
You can write the following airdrop contract to achieve desired result:
Users send stable coins to your airdrop contract. Addresses of these users should be stored in some place. You can store addresses and amounts of token buyers automatically (in arrays on the blockchain - address[] buyers, uint256[] amounts).
If you want users to click on button on website to receive available amount of tokens, your airdrop contract should have a method to send right amount of your token to caller if the caller sent stable coins before. This method should check, if msg.sender is in buyers (check in array can be expensive, you can create a buyers map only for this check) and if airdrop date has come (you can save timestamps in seconds in some array and check if any date has come via comparison with block.timestamp). If both requirements are met, contract sends tokens from your balance (transferFrom) or from its balance (transfer) following the exchange rate.
If you want send the transaction by yourself to give all tokens to buyers, you can make the method, which can be called only by you (Ownable will be very helpful). Inside this method, contract goes through buyers array and send amount[buyerIndex]*exchangeRate to each of them. This method doesn't require users to click on any buttons, but can be very expensive in gas and hence for you.
Related
I am searching for an efficient way to track contract transactions.
Specifically, I want to receive an immediate notification when a specific function with a specific parameter is executed.
Any ideas or suggestions?
The most efficient approach is to listen for new blocks and fetch every transaction from the block via GraphQL (I assume you use geth) which then gives you the block header, transaction and transaction receipt in a single http call.
From there you can ABI decode any transaction input which matches your function signature to obtain the function parameters and join that with the tx status from the receipt.
I am personally writing a similar component (https://github.com/grassrootseconomics/cic-chain-events/) to track ERC20 transfers and notify users (SMS, Telegram, e.t.c). You can borrow and extend concepts from it.
Run your own node
Subscribe to WebSocket hook to receive a notification for every transaction
Check if the transaction matches your parameters
if within your smart contract function there are events emitted with the inputs that your user provide, then it will be possible to listen to those events (and thus your function call) and the corresponding transaction in real-time with Moralis Streams API.
Essentially to work with this, you will need a webhook where Moralis will be able to stream those events and transaction data constantly. To test it out really quickly, you can use https://webhook.site as a test webhook.
To get started with Streams API, you can follow this tutorial right here https://docs.moralis.io/streams-api/getting-started
Hope this helps!
I would like to transfer ERC20 tokens from a wallet who don't own ETH to another wallet who own ETH and who can pay gas fee.
Do you know if it is possible to made a transfer of ERC20 tokens and to let the receiver wallet pay fees ?
TLDR: Not possible, unless the token contract explicitly allows it. Or unless the token holder is also the block producer.
Transaction fees are paid in ETH (or generally, native currency of the network - for example BNB on Binance Smart Chain, MATIC on Polygon, ...). So in most cases, you need to pay ETH to execute either the transfer() function if you want to send the tokens from your address, or the approve() function if you want someone else to transfer tokens from your address.
Very few token contracts implement delegated transfer mechanism on top of the ERC20 standard. There's currently no standardized way to perform a delegated transfer, so each contract might have a different implementation. The token holder uses their private key to sign a predetermined message saying how many tokens they want to transfer to which address. The message also usually contains a nonce or a timestamp to prevent signature replay attack. Token holder passes the message offchain to the transaction sender, and then the transaction sender executes a function of the token contract built specifically for delegated transfers (note that the transaction sender pays the fee to execute this function). The contract validates the signature, and performs the transfer. Again, most token contracts do not implement this mechanism.
One more exception from the rule is a block producer. When you create a new block, you can fill it with transactions not only from the mempool but also with your own transactions. You can build a transaction with 0 gas price, and then include it in the block that you're producing. This way you're also able to send tokens for free.
I have to develop an NFT minting contract with a whitelist system where we can set a variable amount of mint allowance per address.
It would be easy to achieve by setting manually in the contract with something like:
mapping(address => uint) allowancePerAddress
But as it's on Ethereum this solution would not be very cost efficient as we would need to store a couple hundreds of entries manually.
Is there another way, through signature for example to achieve this so it would be cost efficient for both the project and the minter ?
Signatures serve for checking the integrity of a message and also validate the emitter of the message, so Im not sure how would you accomplish using signatures, mainly because you'll need to set a value for each address, and keep track of them in the contract.
What you can do is create a constant that would be the default allowance, and when someone mints their first token you can update their allowance value during that transaction.
Yet, if what you want is to set up a custom value for each address, and you have a high amount of them, you can either do it on deploy, on the constructor or create a function that receives an array of Struct {address, allowance}, and set every address on a loop.
If you are using the ERC-721 standard, what is the prefer method determining which tokens the address owns in a DAPP.
Currently I'm request all the Transfer Events for an address and basically sorting them into transfer in and transfer out, and then using that to determine which tokens the user owns.
Is there a simpler way I missed.
Transfer events may be emitted also by contracts that are not ERC-721 tokens, or some noname tokens that you might not be interested in.
The actual token ownership is stored in the tokens contracts (and not the DAPP contract).
So your current approach is pretty much as straightforward as it can get, if you want to automatically keep track of all tokens that the address currently owns (and some false positives as well).
Note: This is also similar to the approach of Etherscan, which listens to all Transfer event logs and if the sender contract is listed in their database of tokens, they use the event log data to update balances of the sender and recipient.
If you're willing/able to create and maintain a list of tokens that you want to follow, I'd recommend a simpler approach:
Define the list of followed token contract addresses (e.g. ECF or RARI)
For each of these token contracts, call balanceOf(<your_dapp_address>) that returns amount of tokens that the <your_dapp_address> currently owns.
Everyone can create ethereum token by solidity codes but don't know how can this token integrate as payment gateway in ecommerce website.
For real project . This token need frontend web wallet /android wallet and integration to every website as payment.
Plz suggest me .how can find this way.
What need more to study.
Token is not a payment gateway. If i understand your question correctly, you are asking, how can you interact with a token that you have created through Solidity from frontend. One use case would be how people can use the token that you have created to purchase some item. For this the users should already be holding the tokens. This can be bought from an ICO or from an exchange. Basically there's a couple of functions in ERC20 token i.e., approve() and transfer() that will approve apps like exchanges to perform transactions on behalf of the owner of the token. Once the users have those tokens they can purchase items from it. Again, you have to write the logic how and what you expect users to do.
ERC20 Token is works likes Currency.And solidity is a programming language. which we used for write the smart contract. if you want to invoke your function then you need to create wallet account ,after that you can do transaction using with web3js. you can get ether for testing purpose from faucet.Basically these are functions in ERC20 token i.e., approve() and transfer() that will perform transactions
I don't suggest using ERC20 tokens as payment method.
Ethereum network is not fast enough,you need 30 confirmations to make sure you received the token, some times the delay can be 1 day
Cost is high, when you transfer token ,usually you have a smart contract, it costs lots of gas
Ether price is not stable, it drops 90% of value from Jan 2018 to Dec 2018. it will be hard for estore to maintain profit.
However if you still want to do that, yes, you can create your own gateway using tokens as your accepted currency.