> For the complete documentation index, see [llms.txt](https://calnix.gitbook.io/eth-dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://calnix.gitbook.io/eth-dev/ercs-and-eips/landing/erc-1271.md).

# ERC-1271

ERC-1271, which allows for on-chain signature verification for Smart Contracts (since contracts do no have private keys).

* The verifying contract would get passed in the 32-byte hash that it wants to verify along with an implementation dependant byte array - domain seperator.&#x20;
* We expect a return of the bytes4 magic value `0x1626ba7e` when function passes.
* signer contract(multi-sig) must implement `isValidSignature` and return the `magicValue`
  * up to the contract to implement the logic of what determines a valid signature
  * if its multi-sig: could be concatentation of the various users' signatures

{% hint style="info" %}
It's essential to understand that you never will be able to sign with your smart contract account. Only we will create a system to delegate the signature to another account in the name of your smart contract.
{% endhint %}

#### IMplementation example:

<figure><img src="/files/JhA6Slt6i9BMGXQF2zT5" alt=""><figcaption></figcaption></figure>

![](/files/pmmlzkkrWHlwPulgc4rw)

For example we would have to incorporate the following:<br>

```solidity
{...}
import {Address} from "@openzeppelin/contracts/utils/Address.sol";
import {IERC1271} from "@openzeppelin/contracts/interfaces/IERC1271.sol";
{...}


if (Address.isContract(sellOrder.signer)) {
    (bool success, bytes memory data) = sellOrder.signer.staticcall(abi.encodeWithSelector(IERC1271.isValidSignature.selector, digest, abi.encodePacked(r, s, v));
        
    if (!success) revert MISSING_VALID_SIGNATURE_FUNCTION_EIP1271;
    
    bytes4 magicValue = abi.decode(data, (bytes4));
    // must return the bytes4 magic value 0x1626ba7e when function passes
    if (magicValue != 0x1626ba7e) revert SIGNATURE_INVALID_EIP1271;
```

* &#x20;It is established in the standard that in case of success, the function must return the value `0x1626ba7e`&#x20;
* This is not a random value. It is the signature of the function `isValidSignature(bytes32,bytes)`

### Links

* <https://ethereum.stackexchange.com/questions/135761/need-help-on-how-eip-712-works-and-where-are-signatures-stored>
* <https://ethereum.stackexchange.com/questions/27571/sign-data-with-a-contract-account>
* <https://ethereum.stackexchange.com/questions/11252/smart-contract-transaction-signature>
