Skip to content

Ethereum JSON-RPC

Passes allows apps to make requests directly to users. This pattern is powerful for building features backed by blockchains like Ethereum, since Pass Providers can implement signatures using the same kind of cryptography blockchains use.

In this example we'll define a request topic called org.ethereum.json-rpc-request, whose body can be any Ethereum JSON-RPC request:

typescript
import { RequestTopic } from '@passes/reqs';

const ethJsonRpc = new RequestTopic<EthJsonRpc2Request, EthJsonRpc2Result>({
  id: 'org.ethereum.json-rpc-request',
  requestBodyCodec: Codecs.Json,
  resultBodyCodec: Codecs.Json,
});

// Request the user to send 0.02 ETH to samy.eth
const result = await ethJsonRpc.sendRequest({
  method: 'eth_sendTransaction',
  jsonrpc: "2.0",
  id: 1,
  params: [{
    to: '0x7Ee54D537BDF322DcEe8c986Aa12E053D41De30A',
    value: '0x2386F26FC10000',
  }],
});

if (result.status === 'accepted') {
  // `txHash` is the hash of the ethereum transaction sent by the user via their Pass Provider
  const { result: txHash } = result.body;
}
Interactive Example
This demo requests to send a (fake) Ethereum transaction.
Click "Send Request"
The Pass Request will appear here