Nethereum.GSN
NuGet:
Nethereum.GSN| Source:src/Nethereum.GSN/
Nethereum.GSN
Gas Station Network is the ultimate solution for Ethereum decentralized applications. It removes the barrier between users and dApps but increases the complexity of dApps.
Pre-requirements
- Contract should be GSN-capable
- Contract should have positive balance in RelayHub. It can be done via CLI or
RelayHubHelperin the projectRelayHubHelper.DepositRelayHub(
"ED3...", // Private key of sender
"https://rinkeby.infura.io/v3/...", // RPC Endpoint
"0xD216153c06E857cD7f72665E0aF1d7D82172F494", // RelayHub address (https://gsn.openzeppelin.com/relays)
"0x...", // Contract address
Nethereum.Web3.Web3.Convert.ToWei(1) // Amount
);
Getting started
In order to add GSN support to Nethereum Web3 instance, follow the next steps:
- Initialize Web3 with
RpcClientparamenter onlyvar client = new RpcClient(new Uri("https://rinkeby.infura.io/v3/..."));
web3 = new Web3(client); - Initialize
GSNTransactionManagervar options = new GSNOptions { UseGSN = true };
var relayClient = new RelayClient(options.HttpTimeout);
// Discovers relays registered on the RelayHub via its events
var relayQuery = new RelayQuery(options.RelayLookupLimitBlocks, web3.Eth, relayClient);
var relayHubManager = new RelayHubManager(web3.Eth, relayQuery);
// The Relayer selects a ready relay by policy and validates the recipient balance
var balanceValidator = new RecipientBalanceValidator(web3.Eth);
var relayer = new Relayer(relayHubManager, balanceValidator, new DefaultRelayPolicy());
var transactionManager = new GSNTransactionManager(
options,
relayer,
web3.Eth,
web3.Client,
relayClient,
"ED3..." // Private key of sender
); - Set Interceptor of Web3 instance
web3.Client.OverridingRequestInterceptor = new GSNTransactionInterceptor(transactionManager);