SolarPath supports HTTPs access to the Ethereum network, the following example uses curl to interact with Ethereum:
curl https://eth-mainnet.solarpath.io/v1/YOUR-API-KEY \
-X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc": "2.0", "id": 1, "method": "eth_blockNumber", "params": []}'
var Web3 = require('web3');
var url = 'https://eth-mainnet.solarpath.io/v1/YOUR-API-KEY';
var httpProvider = new Web3.providers.HttpProvider(url);
var web3 = new Web3(httpProvider);
web3.eth.getBlockNumber().then((result) => {
console.log("Latest ETH block: " + result);
});
var ethers = require('ethers');
var url = 'https://eth-mainnet.solarpath.io/v1/YOUR-API-KEY';
var etherProvider = new ethers.providers.JsonRpcProvider(url);
etherProvider.getBlockNumber().then((result) => {
console.log("Latest ETH block: " + result);
});
const https = require('https');
const myKey = 'YOUR-API-KEY';
const data = JSON.stringify({
"jsonrpc":"2.0","method":"eth_blockNumber","params": [],"id":1
});
const options = {
host: 'eth-mainnet.solarpath.io',
port: 443,
path: '/v1/' + myKey,
method: 'POST',
headers: {'Content-Type': 'application/json'}
};
const req = https.request(options, res => {
console.log(`status code: ${res.statusCode}`);
res.on('data', d => {
process.stdout.write(d);
});
});
req.on('error', error => {
console.error(error);
});
req.write(data);
req.end();
Web3j web3j =
Web3j.build(new HttpService("https://eth-mainnet.solarpath.io/v1/YOUR-API-KEY"));
EthBlock ethBlock =
web3j.ethGetBlockByNumber(DefaultBlockParameterName.LATEST, false)
.send();
System.out.println("Latest ETH block: " + ethBlock.getBlock().getNumber());
package main
import (
"fmt"
"log"
"github.com/ethereum/go-ethereum/rpc"
)
type Block struct {
Number string
}
func main() {
client, err := rpc.Dial("https://eth-mainnet.solarpath.io/v1/YOUR-API-KEY")
if err != nil {
log.Fatalf("Could not connect to SolarPath: %v", err)
}
var lastBlock Block
err = client.Call(&lastBlock, "eth_getBlockByNumber", "latest", true)
if err != nil {
fmt.Println("Cannot get the ETH latest block:", err)
return
}
fmt.Printf("Latest ETH block: %v\n", lastBlock.Number)
}
from web3 import Web3, HTTPProvider
web3Provider = Web3(HTTPProvider('https://eth-mainnet.solarpath.io/v1/YOUR-API-KEY'))
print ("Latest ETH block ", web3Provider.eth.blockNumber)