Example Guestbook contract using EIP-712 signatures
This repository houses a Truffle project.
It contains the following core components:
Guestbook.solsmart contract in Solidity using @openzeppelin/contracts for EIP-712 verification.guestbookUtils.jshelpers for performing signature operations for a given deployedGuestbook
- There's no
Migrations.sol. Yep 697D , that file is completely optional. - Compiler version is specified as
version: "pragma". Did you know you could do that? 😄 - Ignore the weird RPC URL. No secret unreleased features here. 🤫
- The
console:section intruffle-config.jsis recent new functionality. Pretty handy!
Aggregates signed log entries. This contract defines an EIP-712 schema and verifies the validity of the signature for each entry.
Anyone may spend gas to submit a signed guestbook log from anyone else, as long as the signature and message match.
This module serves as a truffle console "require" hook, adding the
forGuestbook global function to the console scope.
-
Run
truffle consoleortruffle develop -
Ensure you have run migrations (i.e. with
truffle migratecommand) -
Initialize utils:
// get deployed guestbook truffle(develop)> const guestbook = await Guestbook.deployed(); // pass instance to function defined by "require" hook truffle(develop)> const utils = forGuestbook(guestbook); // read current guestbook logs truffle(develop)> utils.read(); // sign message and capture result to variable truffle(develop)> const signedMessage = await utils.sign("hi!"); // submit signed message in transaction to save truffle(develop)> utils.submit(signedMessage); // read guestbook logs again and see new entry truffle(develop)> utils.read();