0

I have a smart contract which have a function to allow/disallow user to send ether to my contract. By default all ETH address are allow to send ether to smart contract.

But, if I want to disallow some ETH address not to send ether, I have to write data on to the blockchain.

The same I want to do it from my WEB APP using web3.js

Can anyone provide me with example for the same.

Thanks In Advanced .......

1
  • 1
    Please do not close with "unclear what you are asking" if you didn't make an effort with user to correct the question. We are all learning, and not everyone has a perfect english.
    – Ismael
    Feb 21, 2018 at 2:33

3 Answers 3

0

Create a mapping of the user's address and their ability to pay, make the default value True to allow them to deposit Ether, do a simple comparison of if (arrayOfUsers[UsersAddress] == True){allow deposit} else{don't allow deposit}

6
  • Want to do it from client side using web3 ?? Feb 20, 2018 at 8:57
  • You'll call it the function via the front end but the front end itself won't actually edit the variable, if the variables are on the Ethereum network it'd make sense to edit them on the Ethereum network
    – JAG
    Feb 20, 2018 at 9:00
  • Yes, but I can send the variable value as a parameter and change it on ethereum network. Am I right ???? Feb 20, 2018 at 9:14
  • Yes, you can. Send it in the data field when calling the function
    – JAG
    Feb 20, 2018 at 9:18
  • Please can you provide me with example how to do it .... Thanks for your support Feb 20, 2018 at 9:22
0

enter image description here

Not sure if the question is still open, if so, maybe you can make a list ^ and monitor smart contract events with Web3. Hope it helps ;)

0

Using a mapping for authorised addresses you can implement a user controlled contract to deposit ethers. Below contract code can be used for this.

//SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

contract TestContract {
    address private _owner ;
    mapping (address=>bool) allowedAddresses;

    constructor() {
        _owner = msg.sender;
    }
    receive() external payable {
        require(allowedAddresses[msg.sender], "Not aurthorised to deposit ether");
    }

    modifier onlyOwner() {
        require(msg.sender == _owner, "This transaction MUST be called from owner's account.");
        _;
    }

    function modifyFundDepositStatus(address accountAddress, bool status) external onlyOwner {
        require(accountAddress != address(0x0), "Not a valid address");
        allowedAddresses[accountAddress] = status;
    }
}

For Web3.js you can call modifyFundDepositStatus() method to allow/disallow an address to deposit funds in the contract.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.