How does uniswap call the approve function - ethereum

I am trying to build a no-code tool for users, I want to be able to transfer tokens on the user's behalf.
anytime I call the IERC20(token address).approvefunction, my metamask does not a return a screen like the attached image and the IERC20(token address).transferFrom function does not execute.
Approve function
tps://i.stack.imgur.com/NfyMC.png

Calling approve() function from within your contract would just approve tokens to be spend from your contract address - not from the user.
You need to invoke MetaMask popup from your frontend app - not from the contract.
Either using their request method, requesting a transaction to the token contract, with data field of the approve() function and its arguments.
Or with more high-level approach: Creating a frontend instance of web3js, ethers.js, or whichever library you prefer, connecting to the window.ethereum local provider, and then invoking the approve() function on the token contract from here. This will also open the MetaMask popup windows asking the user to sign the transaction.

Related

How do I access a plain Ether transaction event in a Solidity Ethereum smart contract dApp?

When a user sends some Ether to a smart contract/dApp address, is there a way I can access that transaction in my smart contract? Like a built-in method that's invoked, that I can add some code to?
My ideal work flow, if it's possible:
User sends Ether to my dApp address.
A function is invoked in my smart contract code.
Within that function, I can create some logic, like add their address to some state, etc.
Ideally, I want to avoid a user having to invoke a particular public function of the contract, but instead just send Ether to the dApp address.
If the user has to invoke a particular function, I have to start thinking about services like MEW, or I have to build a web2 frontend app that integrates with the MetaMask browser extension or something. This seems like a lot of work, but is this the way it has to be?
There is the receive() special function that gets executed when you send ETH to the contract address and not specify any function to execute (i.e. the data field of the transaction is empty).
You can get the sender address through the msg.sender global variable and the amount through msg.value.
pragma solidity ^0.8;
contract MyContract {
mapping (address => uint256) contributions;
receive() external payable {
contributions[msg.sender] += msg.value;
}
}

Is there a service that will call a webhook when a transaction occurs with an eth wallet

I am wondering if there are any services or websites that will automatically monitor an Ethereum wallet and when a transaction occurs with it (either in or out) it calls a specified web hook?
Defender Sentinel from Openzeppelin monitors function calls and events on contracts and can trigger webhooks, emails, slack ect.
It doesn't seem to work on non-contract addresses though.
https://docs.openzeppelin.com/defender/sentinel
Alchemy Notify seems to be able to do that with non-contract addresses.
https://docs.alchemy.com/alchemy/guides/using-notify

How can i store a contract address

I have create a Voting Dapp using web3j and ganache, but their is a small problem. I decide to deploy a voting contract every time a new election begin, and there will be a administrator who control the deploy of the contract and the begin and end of the election. So when the voting contract is deployed, only can the administrator get the contract contract address. how can I send the address to normal citizens so they can call the smart contract.
I thought of storing the contract address in a normal database, but if the database is hacked or destroyed, the whole dapp would crash.
Is there any function in web3j that I can store a string in the blockchain itself?
ps. I saw the web3j.dbputString function but I have no idea how to use it.
private String deployContract(Web3j web3j, Credentials credentials) throws Exception {
return Election.deploy(web3j, credentials,GAS_PRICE,GAS_LIMIT).send().getContractAddress();
}
here is the contract deployed segment.
A common design pattern is called Factory. You can have a smart contract that deploys other contracts. This will generate an event that is visible to the user. See Uniswap Factory.
Alternative you can just make the contract constructor to evit an emit and that is caught by the user frontend.

Why msg.sender has the address of the account which has deployed the contract (and not the one's which interacts with it)?

I am currently developing a dapp on ethereum. From what I know msg.sender should has the value of the account who interact with it. However, it keeps the value of the deployer's account.
I am using metamask and solidity ^0.4.24. I am deploying the contact using truffle framework and also Ganache GUI as my virtual node
function getMe() public view returns(address){
return msg.sender;
}
So, I expect this code to return the hash of the account which is interacting with the contract but instead I am taking back the address of the acount which deployed it
msg.sender contains the value of the address of the caller. You must be deploying and interacting from the same account, probably using accounts[0].

Can a smart contract automatically send message to an user address in ethereum blockchain

I'm a new beginner in the ethereum Blockchain.
I want to implement a smart contract that verifies the authenticity of a user and then send a message to a cloud service (with is the smart contract creator) in case of positive verification to grant access to the user.
My question is it possible for a smart contract to return results of his methods invocation to another blockchain user and how we can do it?
A smart contract cannot make calls outside of the blockchain. i.e., you cannot have it call an http endpoint or something similar.
In ethereum, the usual way of achieving something like this is:
Have the user make a transaction passing relevant data to your smart contract
The smart contract runs whatever verification logic it must on that data
The smart contract logs an Event
You have an ethereum node that your code connects to and listens for these events.