Jaswinder Singh
Jaswinder Singh

Reputation: 41

Pagoda relayer implementation throwing 422 server error

I am trying to run a simple example on the Pagoda relayer on NEAR Protocol, here is the relayer repo I cloned and I am running locally - https://github.com/near/pagoda-relayer-rs

This is my JS script that I am running to make a simple transfer via the relayer. https://gist.github.com/jaswinder6991/5b10f5db919846d26ca7118cb6a9b5ce

I get this error when I run this script:

Response {
  size: 0,
  timeout: 0,
  [Symbol(Body internals)]: {
    body: PassThrough {
      _readableState: [ReadableState],
      _events: [Object: null prototype],
      _eventsCount: 2,
      _maxListeners: undefined,
      _writableState: [WritableState],
      allowHalfOpen: true,
      [Symbol(kCapture)]: false,
      [Symbol(kCallback)]: null
    },
    disturbed: false,
    error: null
  },
  [Symbol(Response internals)]: {
    url: 'http://127.0.0.1:3030/relay',
    status: 422,
    statusText: 'Unprocessable Entity',
    headers: Headers { [Symbol(map)]: [Object: null prototype] },
    counter: 0
  }
}

Upvotes: 1

Views: 69

Answers (1)

Vlad Frolov
Vlad Frolov

Reputation: 7756

According to the pagoda-relayer-rs implementation, the body should be in the following format:

{
  "signed_delegate_action": "base64-encoded-signed-delegate-action"
}

so here is the code (did not test it, but it should work):

return await fetch('http://127.0.0.1:3030/relay', {
      method: 'POST',
      mode: 'cors',
      body: JSON.stringify({
        signed_delegate_action: Buffer.from(encodeSignedDelegate(signedDelegate)).toString("base64"),
      })
      headers: { 'Content-Type': 'application/json' },
    });

Upvotes: 1

Related Questions