This is the server component of a GasStation
npm install ethereumgasstationserver
See the repo https://github.com/EthereumGasStation/ethereumgasstation for instructions on how to deploy your gasstation contracts and create the neccesary Ethereum accounts.
You can set a number of environment variables to configure the script:
WEB3HOSTWS="ws://localhost:8546"
CONTRACTADDRESS="0x7433c7c768be4025ab791fb7b2942c3d9e309f3e"
PRIVATEKEY="11223344"
PORT=8899
Check / modify the settings in the enclosed .env-dist file
The Ethereum node connects through a websocket on localhost
port 8546
ethereumgasstationserver \
--web3hostws "wss://ropsten.infura.io/ws" \
--port 8887 \
--contractaddress 0x0000 \
--privatekey abc
Type ethereumgasstationserver -h
for more info about the available parameters.
Just type ethereumgasstationserver
to start it up.
It will start a REST server that implements the following API:
GET /info/<address>
Returns the configuration of this gasstation & the tokens that you could use this gasstation API with. It checks if the address fits the criteria, and has a balance of the given token. It returns all the neccesary info to start using the gasstation with this token.
If you want to get generic info on the gasstation - don't provide the address
parameter
address
: (String) the pubkey you want to get info for.
GET /info
Response code : 200
{
"uplift": 66,
"netid": 3,
"gasstationaddress": "0x5f0f9749192eee39978f14a0fef0e960cce45f50",
"maxgas": "100000000",
"availablegas": "1000000000000000000",
"tokens": [
{
"ticker": "swarm-city",
"address": "0x7932236cc4e5dbd840d9a52b009fed3582d4bf4f"
}
]
}
uplift
: (Number) The uplift in percent that this gasstation takes on the market pricenetid
: (Number> the network ID this gasstation is connected togasstationaddress
: (String) the address of the accompanying gasstation smart contractavailablegas
: (String) The amount of gas still present in this gassttionmaxgas
: the max amount of gas you can request in a request to fill up your accounttokens
: An array containing the ticker + Ethereum token => address pairs that this gasstation accepts.
Example: GET /info/0x702029796b00f50BcFCE9b0Bb0C402bc453595D8
Response code : 200
{
"uplift": 66,
"netid": 3,
"gasstationaddress": "0x5f0f9749192eee39978f14a0fef0e960cce45f50",
"maxgas": "100000000",
"availablegas": "1000000000000000000",
"tokens": [{
"ticker": "swarm-city",
"address": "0x7932236cc4e5dbd840d9a52b009fed3582d4bf4f",
"balance": "1000000000100000000"
}]
}
In the case that the address is good for using the gasstation, the tokens array will be decorated with the token balance of the specific address.
Example: GET /info/0x5f0f9749192eee39978f14a0fef0e960cce45f50
Response code : 403
{
"uplift": 66,
"netid": 3,
"gasstationaddress": "0x5f0f9749192eee39978f14a0fef0e960cce45f50",
"maxgas": "100000000",
"availablegas": "1000000000000000000",
"accountbalance": "1000000000000000000",
"error": {
"code": 1,
"message": "account is a contract"
}
}
error.code
can be one of the following:
1 : ACCOUNT_IS_CONTRACT
The given account is a smart contract. This hinders the correct calculation of the cas cost to do the exchange - so the gasstation does not allow smart contracts to be filled-up.2 : ACCOUNT_IS_NOT_EMPTY
The given account already has an ETH balance. It does not need gas.3 : ACCOUNT_IS_NOT_UNUSED
The nonce of the account must be 1
POST /fillrequest
Request a quote from the gasstation to exchange your token for gas. The service will reply with an offer that is cryptographically signed by the gasstation maintainer.
{
'address' : '0x1234.......5678',
'gasrequested' : '100000000000',
'tokenoffered' : 'swarm-city'
}
address
: (String) The address you want gas forgasrequested
: (String) The amount of gas you want to receivetokenoffered
: (String) a ticker of a token you want to send in return.
{
'gas' : '100000000000',
'tokens' : '4455666',
'validuntil' : 2304556,
'serversig' : {
'r' : '0x...',
's' : '0x...'
'v' : 12,
}
}
gas
: (String) The amount of gas you will receivetokens
: (String) The amount of tokens that this will costvaliduntil
: blocknumber until when this offer remains validserversig
: The gastank parameters , signed by the gastank signer account
POST /fill
Executes the fillup.
{
'allowancetx' : '0x.... ....',
'address' : '0x1234.......5678',
'tokenoffered' : 'swarm-city'
'gas' : '100000000000',
'tokens' : '445566',
'validuntil' : 2304556,
'serversig' : {
'r' : '0x...',
's' : '0x...'
'v' : 12,
},
'clientsig' : {
'r' : '0x...',
's' : '0x...'
'v' : 12,
}
}
allowancetx
: a signed transaction giving an allowance to the gasstation fortokensoffered
tokens.address
: the address requesting gastokenoffered
: ticker of token offeredgas
tokens
validuntil
: the response from your previous/fillrequest
query.serversig
: The gastank parameters , signed by the gastank signer account - as received from your previous/fillrequest
query.serversig
: The gastank parameters , signed by the client (you) to allow the server to execute the exchange through the smart contract.
- Talk to us in Riot: https://riot.im/app/#/room/#ethereumgasstation:matrix.org