Skip to content

unruggable-labs/ens-gateway-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ens-gateway-template

  1. foundryup
  2. bun i
  3. bun test/local.ts — uses anvil testnet
  4. bun test/testnet.ts — test an L2 deployment

General Setup

  1. bun i @unruggable/gateways
  2. create foundry.toml
  3. add remapping for @unruggable
[profile.default]
#lib = ["lib", "node_modules"] # NOTE: this is the forge default
remappings = [
    '@unruggable/=node_modules/@unruggable/'
]
  1. import the request builder:
import {GatewayFetcher, GatewayRequest} from "@unruggable/gateways/contracts/GatewayFetcher.sol";
import {GatewayFetchTarget, IGatewayVerifier} from "@unruggable/gateways/contracts/GatewayFetchTarget.sol";
  1. attach GatewayFetcher to GatewayRequest
using GatewayFetcher for GatewayRequest;
  1. build a request and fetch it
function abc(string memory input) external view returns ($RETURN_ARGUMENTS) {
    GatewayRequest memory req = GatewayFetcher.newRequest(1);
    req.setTarget(0x...);
    req.setSlot(123);
    req.readBytes();
    req.setOutput(0);
    fetch(verifier, req, this.abcCallback.selector);

    // you should probably pass the inputs along with the callback
    // you can also supply your own gateways(s), or send empty array to use default
    fetch(verifier, req, this.abcCallback.selector, abi.encode(input), new string[](0));
}

⚠️ $RETURN_ARGUMENTS can be anything but MUST match

  1. receive callback and return results
function abcCallback(
    bytes[] calldata values,
    uint8 exitCode,
    bytes calldata data
) external view returns ($RETURN_ARGUMENTS) {
    // if you used req.assert(), req.requireContract(), req.requireNonzero()
    // check if exitCode is nonzero

    // if you passed along extra information, decode it from data
    string memory input = abi.decode(data, (string));

    // parse values and return result
    return (...);
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published