Typescript Example

Required payload:

For definitions, refer to: https://docs.opengsn.org/jsdoc/jsdoc-client.html

// This typescript type represents the full JSON payload required
// by our relay API endpoint. 
type RlyTransactionPayload = {
  relayRequest: {
    request: {
      from: string;
      to: string;
      value: string;
      gas: string;
      nonce: string;
      data: string;
      validUntilTime: string;
    };
    relayData: {
      maxFeePerGas: string;
      maxPriorityFeePerGas: string;
      transactionCalldataGasUsed: string;
      relayWorker: string;
      paymaster: string;
      forwarder: string;
      paymasterData: string;
      clientId: string;
    };
  };
  metadata: {
    maxAcceptanceBudget: string;
    relayHubAddress: string;
    signature: string;
    approvalData: string;
    relayMaxNonce: number;
    relayLastKnownNonce: number;
    domainSeparatorName: string;
    relayRequestId: string;
  };
};

// Usage example:
const examplePayload: RlyTransactionPayload = {
  relayRequest: {
    request: {
      from: '0x1e7D51f413Dd60508352846fCa063f05cB423F8C',
      to: '0x1C7312Cb60b40cF586e796FEdD60Cf243286c9E9',
      value: '0',
      gas: '73380',
      nonce: '1',
      data: '0x0c53c51c0000000000000000000000001e7d51f413dd60508352846fca063f05cb423f8c00000000000000000000000000000000000000000000000000000000000000a017fa37ac5967c642ba02b250f188da83d5613d0e5c0286241ff9aece0503662c2a6146626ce6d182f8b277723d3d638ec12c1fed1f15954ab344a5ecdfba5fd2000000000000000000000000000000000000000000000000000000000000001c0000000000000000000000000000000000000000000000000000000000000044a9059cbb000000000000000000000000e75625f0c8659f18caf845eddae30f5c2a49cb000000000000000000000000000000000000000000000000000de0b6b3a764000000000000000000000000000000000000000000000000000000000000',
      validUntilTime: '1691256746',
    },
    relayData: {
      maxFeePerGas: '1650000000',
      maxPriorityFeePerGas: '1650000000',
      transactionCalldataGasUsed: '19296',
      relayWorker: '0xb9950b71ec94cbb274aeb1be98e697678077a17f',
      paymaster: '0x8b3a505413Ca3B0A17F077e507aF8E3b3ad4Ce4d',
      forwarder: '0xB2b5841DBeF766d4b521221732F9B618fCf34A87',
      paymasterData: '0x',
      clientId: '1',
    },
  },
  metadata: {
    maxAcceptanceBudget: '285252',
    relayHubAddress: '0xe213A20A9E6CBAfd8456f9669D8a0b9e41Cb2751',
    signature:
      '0xd3f7b35fc4985b2a52e4c1b47091b1f5ba947a2159d2da07c7c33b3e54fd5d5e3166847e5a6460fb9e69a90e6531399c5c258e332b6fe1c8157c8e06d527452e1b',
    approvalData: '0x',
    relayMaxNonce: 1424,
    relayLastKnownNonce: 1421,
    domainSeparatorName: 'GSN Relayed Transaction',
    relayRequestId:
      '0x000000001204aa7c5e04714775ca00cad9d6f298f8d43caa291b8f8d1b237e39',
  },
};
const authHeader = `Bearer: ${yourApiToken}`;
const response = axios.post(
  'https://api.rallyprotocol.com/relay',
  examplePayload,
  { headers: { Authorization: authHeader } }
);

Example from the SDK client:

https://github.com/rally-dfs/rly-network-mobile-sdk/blob/main/src/gsnClient/gsnClient.ts

Last updated