14 votes

Deploying abstract contracts and interfaces

You don't try to deploy the abstract interface contract IUser. contract User is IUser {} You deploy (migrate) User. Other contracts can use the abstraction to understand the interface to User. User ...
Rob Hitchens's user avatar
10 votes
Accepted

Interface initiailization

address ckAddress = 0x06012c8cf97BEaD5deAe237070F9587f8E7A266d; KittyInterface kittyContract = KittyInterface(ckAddress); // this initialization is what I don't get That line isn't doing any sort of "...
user19510's user avatar
  • 27.9k
8 votes
Accepted

How to call smart contract from html/Javascript

This might be of some help. http://hypernephelist.com/2016/06/21/a-simple-smart-contract-ui-web3.html There are frameworks that conveniently deal with dependencies, so a lot of us prefer to go that ...
Rob Hitchens's user avatar
8 votes
Accepted

How to get address of contract interface

You can cast the contract to an address type with msg.sender != address(tokenContract)
Tjaden Hess's user avatar
  • 36.9k
8 votes
Accepted

How to override supportsInterface() function if contract needs to support many interfaces?

Your code already overrides the supportsInterface() method well and will cause all the extended contract's methods to be called. This method is also used by the OpenZeppelin Contracts Wizard. If you ...
Qwerty's user avatar
  • 221
7 votes
Accepted

What is the use of a interface or function without implementation?

To economize on bytecode size in calling contracts. To establish standards and ensure compliance. To detect developer errors and oversights. Economize Consider contract Client that will interact ...
Rob Hitchens's user avatar
7 votes

Is there a way to get an interface ID of a Solidity interface using ethersjs?

Here's how I solved it, Ethers v5 & Typescript with OpenZeppelin upgradeable contracts (will work with any type of contract). import { Contract, ContractInterface, ethers } from "ethers"...
GVTopCoder's user avatar
6 votes
Accepted

Anyone knows what does this contract code mean?

approveAndCall for exchanges The approveAndCall / receiveApproval pattern is an old pattern used by exchanges to perform an atomic transfer of funds in a single step. This old method has mostly since ...
supakaity's user avatar
  • 1,458
6 votes
Accepted

Solidity, how to cast SmartContract type to address

Just cast to address: if (address(sampleInterface) != address(0)) {
user19510's user avatar
  • 27.9k
5 votes

Why standard tokens inherit interface?

When the developer makes a contract that inherits the interface, he/she is committing to implementing the functions defined in the interface. Failing to do so will result in undefined functions in the ...
Rob Hitchens's user avatar
5 votes

Solidity function overloading and selectors -- member not unique

I don't know if there's a better way, but you can compute the function selectors directly: bytes4(keccak256("transferFrom(address,address,uint256)")) and bytes4(keccak256("transferFrom(...
user19510's user avatar
  • 27.9k
5 votes

ERC-721 safeTransferFrom is overloaded?

The one without _data doesn't send any data when it calls the other contract. (It sends a zero-length byte sequence.) The one with _data does.
user19510's user avatar
  • 27.9k
5 votes

Interface initiailization

An interface explains to the compiler what functions are available to be called on an external contract without requiring the full source code of that contract to be imported. In this case, the ...
Nanolucas's user avatar
  • 769
5 votes
Accepted

(Sub) contract vs. library vs. struct vs. Interface

There are two separate reasons you would want to separate your logic into more than one contracts / libraries / etc. 1- Modularity, ease of use, ease of maintenance. If you forgo the usage of ...
pabloruiz55's user avatar
  • 7,686
5 votes
Accepted

Variables in interfaces

Some concepts: An abstract contract implements only some of the declared functions, while leaving the others unimplemented. When choosing to use an abstract contract, it is typically because we have ...
goodvibration's user avatar
5 votes

What's the interfaceID for ERC-20?

Short Answer probably 0x36372b07 I think you can add the interfaces like this in your ERC20 Contract constructor, you need to import IERC20 and ERC20 and ERC165 (or ERC165Storage) from OpenZeppelin ...
Majd TL's user avatar
  • 3,197
4 votes
Accepted

Does a Solidity Interface Contract need to implement all functions, or only the function subset used in the contract that implements the interface?

According to my experience in the following code https://gist.github.com/anonymous/c23f944b139a76693abbae261ad577b8 it is enough implementing those ones you are using. In the example: /// ---- ...
Juan Ignacio Pérez Sacristán's user avatar
4 votes
Accepted

How do I check in solidity if interface is supported?

They're referring https://github.com/ethereum/EIPs/issues/165 This has been further developed in https://github.com/ethereum/EIPs/issues/881 The specification there says: We define the interface ...
ivicaa's user avatar
  • 7,519
4 votes
Accepted

Can we modify ERC20 functions?

If you wish your token to be ERC20 compliant you have to have the required functions with the required signatures. That's the whole point of the standard. However, that leaves you with two other ...
Lauri Peltonen's user avatar
4 votes
Accepted

Interfaces in solidity

Just with the import tag the Impl is applying the Interface structure?? No. The source code is loaded. You could use it for several things but you're not using it at all. I´m not doing the ...
Rob Hitchens's user avatar
4 votes
Accepted

In interface does the function listed have to be exactly the same as they are in contract?

Does the function listed have to be exactly the same. No. The interface has to be the same, not the function. You have encountered a subtle difference. It might help to think of the interface as ...
Rob Hitchens's user avatar
4 votes

Why use the Interface (IERC20), instead of the implementation contract (ERC20)?

If you are using the standard functions defined by EIP-20 it doesn't matter either works the same. There are some differences. For example OpenZeppelin's ERC20 implements increaseAllowance that is not ...
Ismael's user avatar
  • 30.5k
4 votes
Accepted

Is there a way to get an interface ID of a Solidity interface using ethersjs?

Currently there is not. You have to xor all function selectors of IMyContract. To make your life easier, you can use ethers.js interface and use its getSighash functions to not have to hash it and ...
ashhanai's user avatar
  • 516
4 votes
Accepted

How to access a public state variable from another smart contract through an interface in Solidity

A public state variable is a combination of two things under the hood: a state variable and an external getter function. The getter is the only part relevant to your contract's ABI so that's what you ...
cameel's user avatar
  • 2,211
4 votes
Accepted

How to check If the smart contract support an interface?

If you have the address of your target contract and want to enforce that the IERC2981 is supported you would do the following: require( IEIP165(target).supportsInterface(type(IERC2981).interfaceId), ...
Richard's user avatar
  • 4,894
4 votes

How to override an interface function that returns a struct with a mapping

Your issue is explained by the documentation. Basically, the getter for : mapping (address => Point) public override foo; is : // return 2 DISTINCT parameters : uint and uint function foo(address) ...
hroussille's user avatar
  • 7,531
3 votes
Accepted

Ethereum address URL

There is an EIP67 that proposes Sending ETH ethereum:<address>[?from=<sender_address>][?value=<ethamount>][?gas=<suggestedGas>] Sending ERC20 tokens ethereum:<address>...
Daniel Luca CleanUnicorn's user avatar
3 votes

Why public variables aren't able to implement interface functions?

Mostly, it's for two main reasons: 1) Functions aren't variables and they are not interchangeable 2) Functions support a lot more things than variables do. Actually variables don't support any ...
Lauri Peltonen's user avatar
3 votes

Variables in interfaces

Interfaces are used when you want to interact with contracts already deployed on the blockchain. You cannot have constructor or variables inside interface contract, only abstract methods (functions ...
Miroslav Nedelchev's user avatar
3 votes
Accepted

How to interact with ERC20 interface?

First, as pointed by @goodvibration, you don't need to recast BAT_TOKEN_ADDRESS to the ERC20 interface since you already did it when assigning its value. Second, your BATSend function should check ...
Elisha Drion's user avatar
  • 2,631

Only top scored, non community-wiki answers of a minimum length are eligible