I'm writing a Defi project. What I want to do is to set an automatic payment. For example, when a lender asks to lend 10 eth, the money would be automaticly sent to him after a month. I have searched a lot but found nothing. Are there any possible remedy? THANKS!
I'm writing a Defi project. What I want to do is to set an automatic payment. For example, when a lender asks to lend 10 eth, the money would be automaticly sent to him after a month. I have searched a lot but found nothing.
You don't. In Ethereum, transactions are always initiated by the user, or Externally Owned Accounts (EOAs).
You program your smart contract in a way that after certain block.timestamp has passed the user can call claim() function that sends him any payment.
You would have to use chainlink keepers for that.
You can put a require statement that will ensure that the eth won't be sent before the 30 days but there is no way to call the function from solidity after 30 days.
Related
I'm fairly new to smart contract development. I am looking for what is the best approach to track total volume sent to a smart contract. The options I have found are;
Emit an event when a transaction with value is sent to the contract
and use ethers.js to filter and aggregate all these events to get
total lifetime volume?
Create a mapping in the smart contract which increments every time a value is sent to the contract?
What would be the best to get this data. The first approach with events would give me the ability to filter on timespans. Does anyone have insight what's the best approach or if there is a better way than the above two.
You have 3 options
First:
you can create variable and add into this variable the value of the transaction and when you need to know all value just return this variable
Second :
If you want to track the volume in real time you can add event listing on this event and then add the result into your db every time someone interact
Third:
you can make queries filtration on the event and callculat all volume
I'm working on a new project that I'm launching soon. The dapp is almost ok, I'm writing the contracts.
But I'm not sure I understood everything, if someone can help me :(
I would like to create a token contract with a supply fix (like 1 million), then make two pre-sales (one with and without whitelist), then a contract to sell on DEX with rewards, staking system, etc.
What is the best way to do this?
Is it possible to :
create the tokens with the first contract
transfer them to the pre sale whitelist contract
make the pre-sale
transfer the remaining tokens to the pre-sale contract without withelist
make the pre-sale
transfer the remaining tokens on the last contract, which will manage all the features of my token + put on a dex
am I right in the way I do it or am I completely wrong ?
If I'm wrong, do I have to do everything in one contract, with specific functions and flags like for the beginning and the end of a pre-dirty ?
if I do everything in one, will some smart guy be able to put the contract on a DEX and add liquidity?
I looked for several ohm/nodes project contracts, I saw the pre-sale contracts but I didn't understand when they create the token because their pre-sale contracts are just sell contracts
and I didn't understand how after the pre sale the main contract takes over
i would like a final contract like that, once the sales are finish
https://snowtrace.io/address/0xf2cfc11093edb5a2dc7f49e70a3a3a9cd4f4fee4#code
if someone can help me, thanks :)
ps : last question, in the contract i dont understand what are payees, shares, addresses and balances variables
This question covers a few different things so I'm going to split my answer up.
Answers:
I looked for several ohm/nodes project contracts, I saw the pre-sale contracts but I didn't understand when they create the token because their pre-sale contracts are just sell contracts
Presale contracts by nature are selling contracts the token contract and the presale contract are generally not the same but there are a thousand ways to do that. They receive x amount of tokens and take payment in say ETH for x tokens.
if I do everything in one, will some smart guy be able to put the contract on a DEX and add liquidity?
Anybody will pretty much always be able to add liquidity for a token because that is external to the token but there are certain ways you can prevent adding liquidity until a certain condition is met say a certain timestamp you just need to detect operations that are swaps/adding liquidity and throw an error.
ps: last question, in the contract I don't understand what are payees, shares, addresses, and balances variables
I am not entirely sure what the purpose of these are for because I am not very familiar with the BRIG protocol.
and I didn't understand how after the pre-sale the main contract takes over
The main contract does not need to take over from the presale contract because the presale contract just runs until all of the tokens are sold and then it just becomes an empty husk.
Other stuff:
In the future please split up your questions across multiple StackOverflow posts.
I am currently the back-end part of a Spring Boot application and i am willing to integrate a payment method. But I can't seem to find the right payment option. I am a beginner in app development and working solo. Do you have any suggestions?
APPLICATION:
I am developing a platform where users can rent a car for a certain period of time. The application will have a react and android application on the frontend. The users can see the different locations of the available cars on a map within the react and android app. They can make a reservation for a car and unlock, drive and lock it after usage.
PAYMENT METHOD:
I am looking for a payment where the users admits to the payment when unlocking the car, but the price of the ride is not known yet. When the user is finished using the car, the price of the ride will be determined by the distance and time driven by the user.
POSSIBLE SOLUTIONS:
-PayPal: there is a possibility to let the user authorize a payment, but capture the funds later. The funds can be altered but only after three days and with a maximum value of 115 percent.
-CreditCard: I read in a lot of posts that storing creditcard information in a database is a big NO.
-Stripe: Don't really know, possible option?
Are there any solutions/examples of how this problem can be solved.
PayPal: there is a possibility to let the user authorize a payment, but capture the funds later. The funds can be altered but only after three days and with a maximum value of 115 percent.
There is no need to wait 3 days, that is a misreading of the authorization and capture documentation. If you have a need to capture over 115% of the initial authorization, contact PayPal about this. But a simple solution is to authorize something close to the maximum value of what you will need to dependably capture.
Stripe has the ability to place a hold on a card and then capture funds up to 7 days later for the amount you captured or less.
Place a hold on a card to reserve funds now but only capture them after your business completes the service. For example, a hotel may authorize a payment in full prior to a guest’s arrival, then move the money when the guest checks out.
When a payment is authorized, the bank guarantees the amount and holds it on the customer’s card for up to seven days.
You could place a hold for the maximum amount you expect to charge for the ride (say $50) then capture the actual amount when the ride completes (perhaps $23.50).
If I have a smart contract that has the addresses of some other smart contracts hardcoded inside it. E.g. maybe my contract has the addresses of some external yield farming vaults that it periodically deposits some balances to.
Now lets say that I want to update that list of addresses and remigrate it without upsetting the operation of the current contract.. what is the best way to do it ?
Ethereum bytecode is immutable, so the simple answer is: You can't update the hardcoded addresses. You'll have to create a new contract and this time save the addresses into variables that you can update later.
I'm trying to create a contract that will dish out regular inflation to all holders of the token. Every x period, it needs to scan the addresses and calculate their inflation, minting new tokens and adding it to their total.
What is the most cost efficient way to do this? Is it cheapest to iterate over the map and update each address, or better to calculate all values in memory and replace the map? Perhaps there is a better way I'm not thinking of.
Not sure how big the map could get, but cost efficiency is key here.
Thanks!
The cheapest way to do this is to have a smart contract function that allows a wallet holder to "claim" their inflation payment. e.g. instead of iterating over every address, you let the wallet holders to do the inflation calculation just for their address.
The cost to you is 0, just have to ensure the smart contract logic is correct
If your intention is to regularly send token/eth to account addresses I urge you to read up on the withdrawal pattern. If you do not follow the withdrawal pattern, a malicious party can set up a smart contract that will get your transaction stuck during the payout.
Instead of sending funds directly you create a map about how much each address is allowed to withdraw. This is very similar to the map about which address holds how many token.
When transferring out of your contract now, only the transaction of the withdrawing party is affected.