### Start GSN Locally Source: https://docs.opengsn.org/javascript-client/getting-started.html Run this command to start GSN on your local ganache instance for testing purposes. ```bash npx gsn start ``` -------------------------------- ### GSN Deployment Configuration Example Source: https://docs.opengsn.org/contracts/custom-deployment Example configuration for deploying GSN 3.0.0-beta.3 on Ethereum Mainnet. Adjust network IDs, relay hub settings, and deployment parameters as needed. ```javascript module.exports = { 1: { environmentsKey: 'ethereumMainnet', relayHubConfiguration: { devAddress: '0x8C1FD2DE219c98f5F88620422e36a8A32f83324E', devFee: 10, pctRelayFee: 30, baseRelayFee: 0 }, // deploymentConfiguration is the only entry not read from the "environments" deploymentConfiguration: { registrationMaxAge: 15552000, paymasterDeposit: '0', isArbitrum: false, deployTestPaymaster: false, minimumStakePerToken: { '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2': '0.01' } }, stakeBurnAddress: '0x8C1FD2DE219c98f5F88620422e36a8A32f83324E' } } ``` -------------------------------- ### Install GSN CLI Source: https://docs.opengsn.org/javascript-client/gsn-helpers Install the GSN CLI package as a development dependency. ```bash yarn add --dev @opengsn/cli ``` -------------------------------- ### Install GSN Dependencies Source: https://docs.opengsn.org/javascript-client/tutorial Install the necessary GSN packages for your project. Use `--dev` for development-specific tools. ```bash yarn add @opengsn/provider @opengsn/contracts ``` ```bash yarn add --dev @opengsn/dev @opengsn/cli ``` -------------------------------- ### Start GSN Relay Server Source: https://docs.opengsn.org/javascript-client/tutorial Initialize GSN contracts and start a local Relay Server. This command also deploys an 'accept-everything' paymaster and writes artifacts to the `build` directory. ```bash npx gsn start ``` -------------------------------- ### Install OpenGSN Contracts Source: https://docs.opengsn.org/contracts Install the OpenGSN contracts package using yarn. Ensure your Solidity version is compatible. ```bash yarn add @opengsn/contracts ``` -------------------------------- ### Configure Truffle Tests with GSN Environment Source: https://docs.opengsn.org/faq/troubleshooting Workaround for 'Unacceptable relayMaxNonce' errors in Truffle tests by using `describe()` or `context()` and managing the relayer lifecycle. This example shows starting and stopping the GSN environment and configuring the RelayProvider. ```javascript contract('mytest', ()=> { before(async()=> { await GsnTestEnvironment.startGsn('localhost') const { forwaderAddress, paymasterAddress } = GsnTestEnvironment.loadDeployment() provider = RelayProvider.newProvider({provider: web3.currentProvider, config: { paymasterAddress}}) }) after(async()=> { await GsnTestEnvironment.stopGsn() }) } ``` -------------------------------- ### Start GSN Local Test Network Source: https://docs.opengsn.org/javascript-client/gsn-helpers Run GSN on a local test network. This command deploys GSN contracts and starts a relay server. Contract addresses are saved to the work directory. ```bash npx gsn start [--workdir ] [-n ] ``` -------------------------------- ### Run GSN Relay Docker Container Source: https://docs.opengsn.org/relay-server/tutorial Start the GSN relay server by running the docker-compose up command. This command downloads and starts the necessary services defined in the docker-compose.yml file. ```bash docker-compose up ``` -------------------------------- ### Monitor HTTPS Portal Logs Source: https://docs.opengsn.org/relay-server/tutorial Check the logs of the 'https-portal' container to monitor the setup progress of the HTTPS server. This is often the slowest component to initialize. ```bash docker ps docker logs ``` -------------------------------- ### Start Hardhat Node Source: https://docs.opengsn.org/javascript-client/tutorial Run a local Hardhat node for development. Use the `--no-deploy` flag if using `hardhat-deploy` to avoid conflicts with GSN contract deployment. ```bash npx hardhat node ``` ```bash npx hardhat node --network hardhat --no-deploy ``` -------------------------------- ### Install @opengsn/contracts Source: https://docs.opengsn.org/javascript-client/tutorial Add the OpenGSN contracts package to your project's dependencies using npm. ```bash npm install @opengsn/contracts --save ``` -------------------------------- ### Get Configuration Source: https://docs.opengsn.org/soldoc/contracts/interfaces/irelayhub.html Retrieves the current configuration settings for the RelayHub. ```APIDOC ## `getConfiguration()` ### Description Retrieves the current configuration of the `RelayHub`. ### Method EXTERNAL #### # Return values - **config** (struct IRelayHub.RelayHubConfig) - The configuration of the `RelayHub`. ``` -------------------------------- ### Recommended Client Configuration for GSN Source: https://docs.opengsn.org/networks/ethereum/goerli Initialize the GSN RelayProvider in your client-side application. This example uses an 'Accept-Everything' paymaster, which is suitable for testing but requires a 'real' paymaster on mainnet. ```javascript const gsnProvider = RelayProvider.newProvider({provider: web3Provider, config: { paymasterAddress: "0x7e4123407707516bD7a3aFa4E3ebCeacfcbBb107" }}) await gsnProvider.init() ``` -------------------------------- ### Check Relay Server Status Source: https://docs.opengsn.org/relay-server/tutorial After setup, browse to the '/getaddr/' endpoint of your relay server to verify its status. The 'ready' field should initially be false, indicating it needs registration. ```bash docker ps docker logs ``` -------------------------------- ### Register Relayer Source: https://docs.opengsn.org/javascript-client/gsn-helpers Fund and register a relay server on a public network. This command requires running after starting your own relayer. ```bash npx gsn relayer-register [--from ] [--relayUrl ] [--stake ] [--unstakeDelay ] [--funds ] [--network ] [ --gasPrice ] [--mnemonic ] [--token ] [--wrap] ``` -------------------------------- ### Mumbai Client Configuration with RelayProvider Source: https://docs.opengsn.org/networks/polygon/mumbai.html Initialize the GSN RelayProvider for a client application on the Mumbai network. This example uses an 'Accept-Everything Paymaster'. Ensure 'web3Provider' is already initialized. ```javascript const gsnProvider = RelayProvider.newProvider({provider: web3Provider, config: { paymasterAddress: "0x086c11bd5A61ac480b326916656a33c474d1E4d8" }}) await gsnProvider.init() ``` -------------------------------- ### Client Configuration for Ethereum Mainnet Source: https://docs.opengsn.org/networks/ethereum/mainnet Initialize a GSN provider for your web3 application using the mainnet paymaster address. This setup is recommended for non-testnet networks. ```javascript const gsnProvider = RelayProvider.newProvider({ provider: web3Provider, config: { paymasterAddress: "0xb536EDbF4B43FF789f9D3215d55690f4015227BA" } }) await gsnProvider.init() ``` -------------------------------- ### Polygon GSN Client Configuration Source: https://docs.opengsn.org/networks/polygon/polygon.html Initialize the GSN provider in your client application for the Polygon network. This example uses an 'Accept-Everything' paymaster. ```javascript const gsnProvider = RelayProvider.newProvider({ provider: web3Provider, config: { paymasterAddress: "0x9e662d0ce3Eb47761BaC126aDFb27F714d819898" } }) await gsnProvider.init() ``` -------------------------------- ### Recommended Client Configuration for GSN Source: https://docs.opengsn.org/networks/arbitrum/goerli-arbitrum.html Initialize the GSN provider in your client application using the specified paymaster address for the Görli-Arbitrum network. This setup enables gasless transactions for your users. ```javascript const gsnProvider = RelayProvider.newProvider({provider: web3Provider, config: { paymasterAddress: "0x9dC769B8cBD07131227b0815BEd3526b1f8ACD52" }}) await gsnProvider.init() ``` -------------------------------- ### GSN Client Initialization with BSC Mainnet Paymaster Source: https://docs.opengsn.org/networks/bsc/bsc-mainnet.html Initialize the GSN provider in your client application using the Binance Smart Chain mainnet's 'Accept-Everything' paymaster address. This setup is for non-testnet networks and requires a valid paymaster. ```javascript const gsnProvider = RelayProvider.newProvider({provider: web3Provider, config: { paymasterAddress: "0x4F74dB5803d2F6C8246262F1e724d51Cb9537c7A" }}) await gsnProvider.init() ``` -------------------------------- ### Run Tests with Hardhat Node and GSN Source: https://docs.opengsn.org/javascript-client/tutorial Execute your contract tests using GSN by running them with a dedicated Hardhat node. This command simplifies the process by starting the node, running tests, and shutting down the node afterward. ```bash run-with-hardhat-node "hardhat test --network dev" ``` -------------------------------- ### Initialize GSN Provider with Arbitrum Paymaster Source: https://docs.opengsn.org/networks/arbitrum/arbitrum.html Initialize the GSN provider for client-side integration on Arbitrum. This example uses the 'Accept-Everything Paymaster' address. Ensure your web3Provider is correctly instantiated. ```javascript const gsnProvider = RelayProvider.newProvider({provider: web3Provider, config: { paymasterAddress: "0x9e662d0ce3Eb47761BaC126aDFb27F714d819898" }}) await gsnProvider.init() ``` -------------------------------- ### Initialize GSN Provider with Optimism Paymaster Source: https://docs.opengsn.org/networks/optimism/optimism.html Initialize the GSN provider in your client application using the Optimism network's paymaster address. This setup is recommended for non-testnet networks. ```javascript const gsnProvider = RelayProvider.newProvider({provider: web3Provider, config: { paymasterAddress: "0x6E4f6878d1188d281F79a8d06e1f52A5cF80b792" }}) await gsnProvider.init() ``` -------------------------------- ### parseServerConfig() Source: https://docs.opengsn.org/jsdoc/global Initializes server configuration parameters from command line, environment variables, or a configuration file. The order of precedence is command line, then environment variables, then the configuration file. The configuration file path must be provided either via the command line or an environment variable. ```APIDOC ## parseServerConfig() ### Description Initializes server configuration parameters from command line, environment variables, or a configuration file. ### Method N/A (Function Call) ### Parameters This method does not explicitly list parameters in the documentation. Configuration is expected to be sourced from: - Command line arguments - Environment variables - Configuration file (path must be provided via command line or environment variable) ### Usage ```javascript parseServerConfig(); ``` ``` -------------------------------- ### constructor Source: https://docs.opengsn.org/soldoc/contracts/arbitrum/arbrelayhub.html Initializes the ArbRelayHub contract with necessary dependencies and configuration. ```APIDOC ## constructor(contract ArbSys _arbsys, contract IStakeManager _stakeManager, address _penalizer, address _batchGateway, address _relayRegistrar, struct IRelayHub.RelayHubConfig _config) ### Description Initializes the `ArbRelayHub` contract. It accepts the `ArbSys` address to facilitate mocking in tests. ### Parameters - `_arbsys` (contract ArbSys): The ArbSys contract instance. - `_stakeManager` (contract IStakeManager): The StakeManager contract instance. - `_penalizer` (address): The address of the penalizer contract. - `_batchGateway` (address): The address of the batch gateway contract. - `_relayRegistrar` (address): The address of the relay registrar contract. - `_config` (struct IRelayHub.RelayHubConfig): Configuration parameters for the RelayHub. ``` -------------------------------- ### Configure Server with Partial Parameters Source: https://docs.opengsn.org/jsdoc/relay_src_serverconfigparams.ts Merges partial server configuration parameters with default values. Use this to create a complete server configuration object. ```typescript export function configureServer (partialConfig: Partial): ServerConfigParams { return Object.assign({}, serverDefaultConfiguration, partialConfig) } ``` -------------------------------- ### Get Penalizer Source: https://docs.opengsn.org/soldoc/contracts/interfaces/irelayhub.html Retrieves the address of the Penalizer contract associated with this RelayHub. ```APIDOC ## `getPenalizer()` ### Description Retrieves the address of the `Penalizer` contract for this `RelayHub`. ### Method EXTERNAL #### # Return values - `Penalizer` address for this `RelayHub`. ``` -------------------------------- ### Get Batch Gateway Source: https://docs.opengsn.org/soldoc/contracts/interfaces/irelayhub.html Retrieves the address of the BatchGateway contract associated with this RelayHub. ```APIDOC ## `getBatchGateway()` ### Description Retrieves the address of the `BatchGateway` contract for this `RelayHub`. ### Method EXTERNAL #### # Return values - `BatchGateway` address for this `RelayHub`. ``` -------------------------------- ### constructor Source: https://docs.opengsn.org/soldoc/contracts/stakemanager.html Initializes the StakeManager contract with delay and address configurations. ```APIDOC ## constructor(uint256 _maxUnstakeDelay, uint256 _abandonmentDelay, uint256 _escheatmentDelay, address _burnAddress, address _devAddress) ### Description Initializes the StakeManager contract. ### Method public ### Parameters #### Path Parameters - **_maxUnstakeDelay** (uint256) - Required - The maximum unstake delay. - **_abandonmentDelay** (uint256) - Required - The delay for abandoned stakes. - **_escheatmentDelay** (uint256) - Required - The delay for escheated stakes. - **_burnAddress** (address) - Required - The initial burn address. - **_devAddress** (address) - Required - The initial development address. ``` -------------------------------- ### Get Relay Registrar Source: https://docs.opengsn.org/soldoc/contracts/interfaces/irelayhub.html Retrieves the address of the RelayRegistrar contract associated with this RelayHub. ```APIDOC ## `getRelayRegistrar()` ### Description Retrieves the address of the `RelayRegistrar` contract for this `RelayHub`. ### Method EXTERNAL #### # Return values - `RelayRegistrar` address for this `RelayHub`. ``` -------------------------------- ### Get Stake Manager Source: https://docs.opengsn.org/soldoc/contracts/interfaces/irelayhub.html Retrieves the address of the StakeManager contract associated with this RelayHub. ```APIDOC ## `getStakeManager()` ### Description Retrieves the address of the `StakeManager` contract for this `RelayHub`. ### Method EXTERNAL #### # Return values - `StakeManager` address for this `RelayHub`. ``` -------------------------------- ### Get Deprecation Time Source: https://docs.opengsn.org/soldoc/contracts/interfaces/irelayhub.html Retrieves the timestamp from which the RelayHub will no longer allow relaying calls. ```APIDOC ## `getDeprecationTime()` ### Description Retrieves the timestamp from which the hub no longer allows relaying calls. ### Method EXTERNAL #### # Return values - `uint256` - timestamp from which the hub no longer allows relaying calls. ``` -------------------------------- ### Initialize GSN RelayProvider Source: https://docs.opengsn.org/javascript-client/getting-started.html Wrap your existing web3 provider with RelayProvider to enable GSN for your application. Configure the paymaster address and logging. ```javascript const { RelayProvider } = require('@opengsn/provider') const config = { paymasterAddress, loggerConfiguration: { logLevel: 'debug' } } const provider = await RelayProvider.newProvider({ provider: web3.currentProvider, config }).init() const web3 = new Web3(provider); ``` -------------------------------- ### Get Worker Manager Source: https://docs.opengsn.org/soldoc/contracts/interfaces/irelayhub.html Retrieves the Relay Manager associated with a given Relay Worker. ```APIDOC ## `getWorkerManager(address worker)` ### Description Retrieves the Relay Manager address associated with a given Relay Worker. ### Parameters #### Path Parameters - **worker** (address) - An address of the Relay Worker. ### Method EXTERNAL #### # Return values - address of its Relay Manager. ``` -------------------------------- ### Download Relay Configuration Files Source: https://docs.opengsn.org/relay-server/tutorial Use curl to download the docker-compose.yml and a sample configuration file for the GSN relay. Ensure the docker-compose.yml is in the home directory and the config file is in a 'config' subdirectory. ```bash curl https://raw.githubusercontent.com/opengsn/gsn/master/dockers/docker-compose.yml > docker-compose.yml mkdir config curl https://raw.githubusercontent.com/opengsn/gsn/master/dockers/config-sample/gsn-relay-config.json > config/gsn-relay-config.json ``` -------------------------------- ### Get Worker Count Source: https://docs.opengsn.org/soldoc/contracts/interfaces/irelayhub.html Returns the number of Relay Workers associated with a specific Relay Manager. ```APIDOC ## `getWorkerCount(address manager)` ### Description Returns the count of Relay Workers associated with a specific Relay Manager. ### Parameters #### Path Parameters - **manager** (address) - An address of the Relay Manager. ### Method EXTERNAL #### # Return values - count of Relay Workers associated with this Relay Manager. ``` -------------------------------- ### GSN Client Configuration with RelayProvider Source: https://docs.opengsn.org/networks/avax/avalanche-fuji.html Initialize the GSN RelayProvider with your web3 provider and the Accept-Everything Paymaster address for the Avalanche Fuji Testnet. Call `init()` to prepare the provider. ```javascript const gsnProvider = RelayProvider.newProvider({provider: web3Provider, config: { paymasterAddress: "0x735719A8C5aF199ea5b93207083787a5B548C0e2" }}) await gsnProvider.init() ``` -------------------------------- ### getMinimumStakePerToken Source: https://docs.opengsn.org/soldoc/contracts/interfaces/IRelayHub.html Gets the minimum stake required for a given ERC-20 token to consider a Relay Manager as staked. ```APIDOC ## getMinimumStakePerToken(contract IERC20 token) ### Description Gets the minimum stake required for a given ERC-20 token to consider a Relay Manager as staked. A zero value means this token is not allowed for staking. ### Parameters #### Path Parameters - **token** (contract IERC20) - Required - An address of an ERC-20 compatible tokens. ### Method external ### Returns - minimum amount of a given `token` that needs to be staked so that the Relay Manager is considered to be 'staked' by this `RelayHub`. ``` -------------------------------- ### Get Paymaster Version Source: https://docs.opengsn.org/javascript-client/tutorial Returns the supported GSN protocol version for the paymaster. Ensure this matches the client's expected version. ```solidity function versionPaymaster() external virtual view override returns (string memory) { return "3.0.0"; } } ``` -------------------------------- ### Initialize TokenPaymasterProvider with PermitERC20UniswapV3Paymaster Source: https://docs.opengsn.org/paymasters/predeployed Use PermitERC20UniswapV3Paymaster for experimental ERC-20 token payments with meta-transaction support. This Paymaster is deployed on Goerli and requires a custom provider. The token address parameter in init() is optional. ```typescript import { GSNConfig } from '@opengsn/provider' import { PaymasterType } from '@opengsn/common' import { TokenPaymasterProvider } from '@opengsn/paymasters' const gsnConfig: Partial = { loggerConfiguration: { logLevel: 'debug' }, paymasterAddress: PaymasterType.PermitERC20UniswapV3Paymaster } const gsnProvider = TokenPaymasterProvider.newProvider({ provider: window.ethereum, config: gsnConfig }) await gsnProvider.init(DAI_TOKEN_ADDRESS) ``` -------------------------------- ### _msgSender() Source: https://docs.opengsn.org/soldoc/contracts/ERC2771Recipient.html Internal method to get the real sender of the call. It returns the actual sender for relayed transactions or `msg.sender` for direct calls. ```APIDOC ## _msgSender() ### Description Returns the actual sender of the current call. For relayed transactions, it extracts the sender's address from `msg.data`. Otherwise, it returns `msg.sender`. ### Method `internal view` ### Return Values - `ret` (address) - The real sender of the call. ``` -------------------------------- ### Get Minimum Stake Per Token Source: https://docs.opengsn.org/soldoc/contracts/interfaces/irelayhub.html Determines the minimum amount of a specific ERC-20 token required for a Relay Manager to be considered staked. ```APIDOC ## `getMinimumStakePerToken(contract IERC20 token)` ### Description Returns the minimum amount of a given ERC-20 token that needs to be staked for a Relay Manager to be considered 'staked' by this `RelayHub`. A zero value indicates that the token is not allowed for staking. ### Parameters #### Path Parameters - **token** (contract IERC20) - An address of an ERC-20 compatible token. ### Method EXTERNAL #### # Return values - minimum amount of a given `token` that needs to be staked so that the Relay Manager is considered to be 'staked' by this `RelayHub`. Zero value means this token is not allowed for staking. ``` -------------------------------- ### Gnosis Chain Client Initialization Source: https://docs.opengsn.org/networks/gnosis/gnosis.html Initializes the GSN provider with a specific paymaster address for the Gnosis Chain network. Requires a pre-existing 'web3Provider'. ```javascript const gsnProvider = RelayProvider.newProvider({provider: web3Provider, config: { paymasterAddress: "0xfCEE9036EDc85cD5c12A9De6b267c4672Eb4bA1B" }}) await gsnProvider.init() ``` -------------------------------- ### Get Gas Limits from Paymaster Source: https://docs.opengsn.org/contracts Implement getGasLimits() in your Paymaster contract to specify gas requirements for preRelayedCall and postRelayedCall, including the crucial acceptanceBudget. ```solidity function getGasLimits() external view returns ( GasLimits memory limits ); ``` -------------------------------- ### CaptureTheFlag Contract Example Source: https://docs.opengsn.org/javascript-client/tutorial A simple CaptureTheFlag contract demonstrating GSN integration. It inherits from ERC2771Recipient and uses _msgSender() to correctly identify the transaction sender. ```solidity import "@opengsn/contracts/src/ERC2771Recipient.sol"; contract CaptureTheFlag is ERC2771Recipient { event FlagCaptured(address previousHolder, address currentHolder); address public currentHolder = address(0); constructor(address _forwarder) { _setTrustedForwarder(_forwarder); } function captureFlag() external { address previous = flagHolder; // The real sender. If you are using GSN, this // is not the same as msg.sender. flagHolder = _msgSender(); emit FlagCaptured(previous, flagHolder); } } ``` -------------------------------- ### Create New Account for Testing Source: https://docs.opengsn.org/javascript-client/getting-started.html Generate a new account address using the provider or web3 for testing transactions without requiring ETH. ```javascript from = provider.newAccount().address ``` ```javascript from = web3.eth.personal.newAccount('pwd') ``` -------------------------------- ### _msgData() Source: https://docs.opengsn.org/soldoc/contracts/ERC2771Recipient.html Internal method to get the real message data. It strips the appended sender address for relayed transactions, otherwise returns the original `msg.data`. ```APIDOC ## _msgData() ### Description Returns the actual message data for the current call. If the call was relayed, it removes the last 20 bytes (the sender's address) from `msg.data`. Otherwise, it returns the original `msg.data`. ### Method `internal view` ### Return Values - `ret` (bytes) - The real `msg.data` of the call. ``` -------------------------------- ### Initialize GSN Provider with BSC Testnet Paymaster Source: https://docs.opengsn.org/networks/bsc/bsc-testnet.html This JavaScript code initializes the GSN provider using a given Web3 provider and configures it with the BSC Testnet's 'Accept-Everything' paymaster address. Ensure `RelayProvider` is imported and `web3Provider` is an initialized Web3 provider instance. ```javascript const gsnProvider = RelayProvider.newProvider({provider: web3Provider, config: { paymasterAddress: "0x735719A8C5aF199ea5b93207083787a5B548C0e2" }}) await gsnProvider.init() ``` -------------------------------- ### Initialize RelayProvider with SingletonWhitelistPaymaster Source: https://docs.opengsn.org/paymasters/predeployed Use SingletonWhitelistPaymaster for simple on-chain rules for GSN integrations. Requires setting the dappOwner in GSNConfig. ```typescript import { PaymasterType } from '@opengsn/common' import { RelayProvider, GSNConfig } from '@opengsn/provider' const gsnConfig: Partial = { loggerConfiguration: { logLevel: 'debug' }, paymasterAddress: PaymasterType.SingletonWhitelistPaymaster, dappOwner: "0x... " } const gsnProvider = RelayProvider.newProvider({ provider: window.ethereum, config: gsnConfig }) ``` -------------------------------- ### Get Forwarder and Paymaster Addresses (Local) Source: https://docs.opengsn.org/javascript-client/getting-started.html Retrieve the deployed forwarder and paymaster contract addresses from the local GSN build artifacts. This is necessary for deploying your contract. ```javascript // assuming this script is in "test" or "src" folder, const forwarder = require( '../build/gsn/Forwarder').address myContract = MyContract.new(forwarder) ``` ```javascript const paymaster = require('../build/gsn/Paymaster').address ``` -------------------------------- ### deposit() Source: https://docs.opengsn.org/soldoc/contracts/interfaces/IERC20Token.html Allows users to deposit funds, typically for wrapped ETH functionality. ```APIDOC ## deposit() ### Description Allows users to deposit funds, typically for wrapped ETH functionality. ### Method external ``` -------------------------------- ### receive() Source: https://docs.opengsn.org/soldoc/contracts/basepaymaster.html Handles incoming native Ether, transferring it to the RelayHub as a deposit. ```APIDOC ## receive() ### Description Handles any native Ether transferred directly to the Paymaster. The received Ether is automatically transferred to the `RelayHub` as a deposit, simplifying deposit management. ### Method `receive()` (external) ``` -------------------------------- ### Use _msgSender() for Sender Address Source: https://docs.opengsn.org/contracts Always use _msgSender() instead of msg.sender in GSN recipient contracts to get the correct user address. msg.sender will be the Forwarder contract. ```solidity contract MyContract is ERC2771Recipient { // ... function _msgSender() internal view virtual override returns (address) { // If the contract is GSN-relayed, _msgSender() will return the original sender. // Otherwise, it will return msg.sender. return ERC2771Recipient._msgSender(); } // ... } ``` -------------------------------- ### Parse Server Configuration Source: https://docs.opengsn.org/jsdoc/relay_src_serverconfigparams.ts Parses server configuration from command-line arguments and environment variables. It merges configuration from a JSON file if specified, applying type conversions. ```typescript export function parseServerConfig (args: string[], env: any): any { const envDefaults = filterMembers(env, ConfigParamsTypes) const argv = parseArgs(args, { string: filterType(ConfigParamsTypes, 'string'), // boolean: filterType(ConfigParamsTypes, 'boolean'), default: envDefaults }) if (argv._.length > 0) { error(`unexpected param(s) ${argv._.join(',')}`) } // @ts-ignore delete argv._ let configFile = {} const configFileName = argv.config as string console.log('Using config file', configFileName) if (configFileName != null) { if (!fs.existsSync(configFileName)) { error(`unable to read config file "${configFileName}"`) } configFile = JSON.parse(fs.readFileSync(configFileName, 'utf8')) console.log('Initial configuration:', configFile) } const config = { ...configFile, ...argv } return entriesToObj(Object.entries(config).map(explicitType)) } ``` -------------------------------- ### execute Source: https://docs.opengsn.org/soldoc/contracts/forwarder/IForwarder.html Executes a verified forward request. ```APIDOC ## execute(struct IForwarder.ForwardRequest forwardRequest, bytes32 domainSeparator, bytes32 requestTypeHash, bytes suffixData, bytes signature) ### Description Executes a transaction specified by the `ForwardRequest` after verifying its validity. If verification passes, the transaction is executed, and the success status and return data of the underlying `CALL` are returned. This method only reverts on verification errors; target contract errors are reported via the returned success flag. ### Method EXTERNAL ### Parameters - **forwardRequest** (struct IForwarder.ForwardRequest) - All requested transaction parameters. - **domainSeparator** (bytes32) - The domain used when signing this request. - **requestTypeHash** (bytes32) - The request type used when signing this request. - **suffixData** (bytes) - The ABI-encoded extension data for the current `RequestType` used when signing this request. - **signature** (bytes) - The client signature to be validated. ### Return values - **bool success**: The success flag of the underlying `CALL` to the target address. - **bytes ret**: The byte array returned by the underlying `CALL` to the target address. ``` -------------------------------- ### Implement Paymaster Contract Source: https://docs.opengsn.org/contracts Create a Paymaster contract inheriting from BasePaymaster to cover meta-transaction fees. Implement preRelayedCall and postRelayedCall methods. ```solidity import "@opengsn/contracts/src/paymaster/BasePaymaster.sol"; contract MyPaymaster is BasePaymaster { // ... function preRelayedCall(Transaction calldata, address, address, uint256, bytes calldata) external virtual override returns (bytes memory context) { // ... } function postRelayedCall(bytes memory context, bool revertReason, uint256 gasUsed) external virtual override { // ... } // ... } ``` -------------------------------- ### _msgSender() Source: https://docs.opengsn.org/soldoc/contracts/erc2771recipient.html Internal method to get the real sender of the current call. It returns the actual sender address, whether the call was made directly or through a trusted Forwarder. This is essential for correctly identifying the originator of a transaction in a relayed environment. ```APIDOC ## _msgSender() ### Description Returns the actual sender of the current call. If the call was made through a trusted Forwarder, it extracts the sender's address from `msg.data`. Otherwise, it returns `msg.sender`. ### Method `internal view` ### Return Values - `ret` (address): The real sender of this call. ``` -------------------------------- ### Import BasePaymaster Contract Source: https://docs.opengsn.org/javascript-client/tutorial All paymasters inherit from BasePaymaster, which handles deposits and relay hub interactions. ```solidity pragma solidity ^0.8.7; // SPDX-License-Identifier: MIT import "@opengsn/contracts/src/BasePaymaster.sol"; ``` -------------------------------- ### getPenalizeBlockDelay Source: https://docs.opengsn.org/soldoc/contracts/Penalizer.html Retrieves the minimum delay between commit and reveal steps for penalization. ```APIDOC ## getPenalizeBlockDelay() ### Description Returns the minimum delay between commit and reveal steps. ### Method `getPenalizeBlockDelay()` ### Response #### Success Response (uint256) - **return value** (uint256) - The minimum delay in blocks. ``` -------------------------------- ### Deploy GSN Contracts Source: https://docs.opengsn.org/javascript-client/gsn-helpers Deploy the singleton RelayHub instance and other required GSN contracts. Saves deployment results to the specified work directory. ```bash npx gsn deploy [--from ] [--workdir ] [--network ] ``` -------------------------------- ### Version Hub Source: https://docs.opengsn.org/soldoc/contracts/interfaces/irelayhub.html Returns the SemVer-compliant version of the RelayHub contract. ```APIDOC ## `versionHub()` ### Description Returns the SemVer-compliant version of the `RelayHub` contract. ### Method EXTERNAL #### # Return values - `string` - SemVer-compliant version of the `RelayHub` contract. ``` -------------------------------- ### receive() Source: https://docs.opengsn.org/soldoc/contracts/BasePaymaster.html Handles incoming Ether transfers to the Paymaster, forwarding them as deposits to the RelayHub. ```APIDOC ## # `receive()` (external) ### Description Any native Ether transferred into the paymaster is transferred as a deposit to the RelayHub. This way, we don't need to understand the RelayHub API in order to replenish the paymaster. ### Method `receive` ```