
Security News
Package Maintainers Call for Improvements to GitHub’s New npm Security Plan
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
@openeth/gsn
Advanced tools
It's a mechanism for dApps to work with gas-less clients. Users are no longer required to install browser extensions, or buy Ether in order to use the dApp.
The dApp owner decides which clients or what calls are allowed, and pays for the calls. It may use its own mechanism to manage its users.
Examples
Its very simple to adapt an existing contract and apps to use the Relays
For a full technical description, see our EIP draft
The client has an account (address and private key) just like any other ethereum account - except that it never has to have any money in it.
It makes an off-chain request to a Relay Service, outside of the ethereum network.
The relay transfers the request to the target contract (through a public RelayHub contract)
The relay gets compensated by the target contract for its effort.
The system is completely decentralized and trust-less: the client doesn't trust on the Relay Service, and the Relay service
doesn't trust neither the client nor the target contract, yet none can compromise the system.
Since clients no longer carry ether, you're not required to use strong wallet - you can keep the client's private key is a local file (cookie). The client can use your local web3 account (e.g. MetaMask), or create a local private-key.
Absolutely. In our "mutual-distrust" model, neither the client or contract has to trust the relay to work correctly, nor the relay trusts the contract or client. All transaction are signed, both by the client (though its account doesn't have to carry any ether) and by the relay.
Neither the relays in the network, nor the RelayHub contract are controlled by Openeth in any way. We will operate relays in the network, to make sure there's availability of relays, but so can anyone else. The relays network is a free market, where relays compete based on transaction fees and quality of service, on equal grounds.
Prerequisites:
Install node pakcages:
yarn
Compile and run tests: (For Docker users)
./dock/run.sh yarn
./dock/run.sh yarn test
The above is a docker wrapper, containing build prerequisites (go
, abigen
, solc
). If you have them installed, you can run instead:
yarn test
Here's how to download and run our modified "MetaToken", modified to demonstrate supoprt for gasless transaction. In the gsn folder do:
./dock/run.sh ./restart-relay.sh web
Configure your MetaMask to Localhost:8545
open your browser to http://localhost:8080/
Notes
restart-relay.sh
script will kill ganache, so you must run truffle migrate && truffle test
again
in the webpack-box project
, to re-deploy the MetaCoin, and fund it with initial ether
(remember: it's the contract that pays for transactions, not the calling webapp!)note that yarn test
above runs the entire suite: it compiles the server, then launches ganache-cli node, deploys the needed component and starts the relay server. then it launches truffle test to run the client tests against the relay server and the contracts on the blockchain.
const Gsn = require( '@openeth/gsn')
const provider = new Gsn.RelayProvider(web3.currentProvider, {} )
web3.setProvider(provider)
//from now on, any transaction through this web3 will go through a relay
MyContract = new web3.eth.Contract(...)
const myContract = await MyContract.at('...')
myContract.someMethod()
A relay client can receive various options:
force_gasLimit
- use specific gas limit for all transactions. if not set, the user must supply gas limit for each transaction.force_gasprice
- if not set, then the client will use web3.eth.gasPrice
with the factor (below)gaspriceFactorPercent
- how much above default gasPrice
to use. default is 20% which means we use gasPrice*1.2minStake
- ignore relays with lower stakeminDelay
- ignore relays with lower stake delayverbose
- show logs of client requests/responsesIn order to support relayed transactions, the contract must implement the RelayRecipient
contract. This way it can check (before the call) the caller, and decide whether to accept the call.
Here's a basic contract, which accepts requests from known users.
contract MyContract is RelayRecipient {
constructor() {
// this is the only hub I trust to receive calls from
init_relay_hub(RelayHub(0xe78A0F7E598Cc8b0Bb87894B0F60dD2a88d6a8Ab));
}
mapping (address => bool) public my_users;
// this method is called by the RelayHub, before relaying the transaction.
// the method should return zero if and only if the contract accepts this transaction, and is willing to pay
// the relay for its service.
// it can check the user, the relay or the actual function call data.
// note that when the RelayHub calls this method, its after it did validation of the relay and caller signatures.
function accept_relayed_call(address relay, address from, bytes encoded_function, uint gas_price, uint transaction_fee ) external view returns(uint32) {
// we simply trust all our known users.
if ( !my_users[from] ) return 10;
return 0;
}
// This is a sample contract method.
// note that when receiving a request from a relay, the msg.sender is always a RelayHub.
// You must change your contract to use get_sender() to get the real sender.
// (its OK if someone calls this method directly: if no relay is involved, get_sender() returns msg.sender)
function my_method() {
require ( my_users[ get_sender() ] );
...
}
}
In the samples/contracts folder there are several sample RelayRecipient implementations for general use-cases.
FAQs
Openeth Gas Stations Network
We found that @openeth/gsn demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
Product
Socket Firewall is a free tool that blocks malicious packages at install time, giving developers proactive protection against rising supply chain attacks.
Research
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.