foundryup
bun i
bun test/local.ts
— uses anvil testnetbun test/testnet.ts
— test an L2 deployment- simple deploy.sh script
bun i @unruggable/gateways
- create
foundry.toml
- add remapping for
@unruggable
[profile.default]
#lib = ["lib", "node_modules"] # NOTE: this is the forge default
remappings = [
'@unruggable/=node_modules/@unruggable/'
]
- import the request builder:
import {GatewayFetcher, GatewayRequest} from "@unruggable/gateways/contracts/GatewayFetcher.sol";
import {GatewayFetchTarget, IGatewayVerifier} from "@unruggable/gateways/contracts/GatewayFetchTarget.sol";
- attach
GatewayFetcher
toGatewayRequest
using GatewayFetcher for GatewayRequest;
- 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
- 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 (...);
}