developers.cloudflare.com Open in urlscan Pro
104.16.2.189  Public Scan

Submitted URL: http://somashop.bbksweet.org/
Effective URL: https://developers.cloudflare.com/web3/how-to/use-ethereum-gateway/
Submission: On September 09 via api from NL — Scanned from NL

Form analysis 0 forms found in the DOM

Text Content

Skip to content
Cloudflare Docs
SearchK
Product directory Learning paths Status Support Log in
GitHub Twitter YouTube
Select theme DarkLightAuto
Web3
 * Overview
 * About
 * Get started
 * How to
    * Overview
    * Manage gateways
    * Subscribe to gateways
    * Use Ethereum gateway
    * Use IPFS gateway
    * Customize Cloudflare settings
    * Restrict gateway access

 * IPFS Gateway
    * Overview
    * Concepts
       * Overview
       * Interplanetary File System (IPFS)
       * DNSLink gateways
       * Universal Path gateway
   
    * Reference
       * Overview
       * Peering
       * Using IPFS with your website
       * Automated deployments
   
    * Troubleshooting

 * Ethereum Gateway
    * Overview
    * Concepts
       * Overview
       * Ethereum network
       * Node types
   
    * Reference
       * Overview
       * Supported API methods
       * Supported networks
       * Rinkeby deprecation
       * Kill Switches

 * Reference
    * Overview
    * Gateway DNS records
    * Gateway status
    * Legacy gateway migration
    * Limits

 * API reference ↗ API

Product directory Learning paths Status Support Log in
GitHub Twitter YouTube
Select theme DarkLightAuto
On this page
Overview
 * Overview
 * Read from the network
 * Write to the network


ON THIS PAGE

 * Overview
 * Read from the network
 * Write to the network

 1. Products
 2. …
 3. Web3
 4. How to
 5. Use Ethereum gateway


USE ETHEREUM GATEWAY

Once you have an Ethereum gateway — meaning that you create a new gateway with a
target of Ethereum — you can interact with different Ethereum networks by
specifying the correct JSON blob for your query.


READ FROM THE NETWORK

The Cloudflare Ethereum Gateway allows HTTP requests where the body of the
request is set to be the JSON body of the request you would like to make. For
example, if you would like to read the block that is at number 0x2244, then your
JSON blob takes the form:

{
  "jsonrpc": "2.0",
  "method": "eth_getBlockByNumber",
  "params": ["0x2244", true],
  "id": 1
}



Each blob use a valid method parameter. The params array here contains the block
number that we would like to locate and a boolean expressing whether each
individual transaction in the block should be shown in their entirety (true) or
as stubs (false).

To send this query to your custom Ethereum Gateway, you could use a cURL
command:

Terminal window
curl https://web3-trial.cloudflare-eth.com/v1/mainnet -H 'Content-Type: application/json' --data '{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["0x2244", true],"id":1}'



You can also write the same query using the JS Fetch API:

await fetch(
  new Request("https://web3-trial.cloudflare-eth.com/v1/mainnet", {
    method: "POST",
    body: JSON.stringify({
      jsonrpc: "2.0",
      method: "eth_getBlockByNumber",
      params: ["0x2244", true],
      id: 1,
    }),
    headers: {
      "Content-Type": "application/json",
    },
  }),
).then((resp) => {
  return resp.json();
});



The response in both cases will be a JSON blob of the form:

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "difficulty": "0x746ef15b66",
    "extraData": "0x476574682f76312e302e302f6c696e75782f676f312e342e32",
    "gasLimit": "0x1388",
    "gasUsed": "0x0",
    "hash": "0xd6bb42034740c5d728e774e43a01f26222e0fcc279c504ca5963dc34fe70f392",
    "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
    "miner": "0xf927a40c8b7f6e07c5af7fa2155b4864a4112b13",
    "mixHash": "0x975da446e302e6da6cedb3fbaa763c3c203ae88d6fab4924e2a3d34a568c4361",
    "nonce": "0x88a7f12f49151c83",
    "number": "0x2244",
    "parentHash": "0x067fd84ecdbc7491bf5ec7d5d4ead361b1f590eec74797a7f90b4a7d7004a48d",
    "receiptsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
    "sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
    "size": "0x21b",
    "stateRoot": "0x828dade2067283e370993ec6a1bda0e65c1310e404a6d5bbb030b596eb80017c",
    "timestamp": "0x55bb040f",
    "totalDifficulty": "0x5c328da43525d",
    "transactions": [],
    "transactionsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
    "uncles": []
  }
}




WRITE TO THE NETWORK

Currently, the Ethereum Gateway allows you to write to the network using the
eth_sendRawTransaction RPC method. This creates a new message call transaction
or a contract creation for signed transactions. The transactions are signed
using a secret key corresponding to your own Ethereum wallet ↗.

Once you have a wallet set up and a method of signing your own transactions, you
can write that transaction to the Ethereum network via the Cloudflare Ethereum
Gateway. Signed transactions use hexadecimal strings of the form:

"0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"



Then you can use your custom Gateway to send the transaction to the network with
a cURL command:

Terminal window
curl https://web3-trial.cloudflare-eth.com/v1/mainnet -H 'Content-Type: application/json' --data '{"jsonrpc":"2.0","method":"eth_sendRawTransaction","params":["0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"],"id":1}'



You could also use a JS Fetch API request:

await fetch(
  new Request("https://web3-trial.cloudflare-eth.com/v1/mainnet", {
    method: "POST",
    body: JSON.stringify({
      jsonrpc: "2.0",
      method: "eth_sendRawTransaction",
      params: [
        "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675",
      ],
      id: 1,
    }),
    headers: {
      "Content-Type": "application/json",
    },
  }),
).then((resp) => {
  return resp.json();
});



(The actual command above will not work — you need to provide your own signed
transaction.)

Edit page
Cloudflare DashboardDiscordCommunityLearning CenterSupport Portal
Cookie Preferences


OUR SITE USES COOKIES

Like most websites, we use cookies to make our site work the way you expect it
to, improve your experience on our site, analyze site usage, and assist in our
marketing efforts. By choosing "Accept All Cookies", you agree to the storing of
all categories of cookies on your device. If you wish to accept or reject some
categories of cookies, please click “Cookie Preferences.”
Cookie Preferences Reject All Accept All Cookies