Skip to content

Commit

Permalink
feat: add eip1193 api
Browse files Browse the repository at this point in the history
  • Loading branch information
snaildarter committed May 12, 2024
1 parent d346419 commit 5253104
Showing 1 changed file with 63 additions and 1 deletion.
64 changes: 63 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import Path from "./utils/path";
* @param isProdUrl is production url
*/
export function init(isProdUrl = true) {
axios.defaults.baseURL = isProdUrl ? "https://EthPaymaster.org" : "https://relay-ethpaymaster-pr-20.onrender.com";
// axios.defaults.baseURL = isProdUrl ? "https://EthPaymaster.org" : "https://relay-ethpaymaster-pr-20.onrender.com";
axios.defaults.baseURL = isProdUrl ? "https://EthPaymaster.org" : "http://localhost";
axios.defaults.headers.common['Content-Type'] = 'application/json';
axios.interceptors.response.use(function (response) {
// return data value
Expand Down Expand Up @@ -69,3 +70,64 @@ export const tryPayUserOperationV1 = (data: UserOpReq): Promise<TryPayUserOpRes
}
})
}

let axiosIndex = 1;
export const getSupportEntryPoint = (network = "Network"): Promise<EntryPointRes | any> => {
return axios.post('/api/v1/paymaster', {
"jsonrpc": "2.0",
"id": axiosIndex++,
"method": "pm_supportEntrypoint",
"params": [
network
]
}).then(res => {
// @ts-ignore
if (res?.code === 200 && res?.data?.length) {
return res.data;
}
return res;
})
}

export const sponsorUserOp = (userOp: { callData: string, initCode: string, nonce: string, sender: string, strategyCode: string }): Promise<any> => {
return axios.post('/api/v1/paymaster', {
"jsonrpc": "2.0",
"id": axiosIndex++,
"method": "pm_sponsorUserOperation",
"params": [
{
callData: userOp.callData,
initCode: userOp.initCode,
nonce: userOp.nonce,
sender: userOp.sender
}, {
strategy_code: userOp.strategyCode
}]
})
}

export const estimateUserOpGas = (userOp: { callData: string, initCode: string, nonce: string, sender: string, strategyCode: string }): Promise<any> => {
return axios.post('/api/v1/paymaster', {
"jsonrpc": "2.0",
"id": axiosIndex++,
"method": "pm_estimateUserOperationGas",
"params": [
{
callData: userOp.callData,
initCode: userOp.initCode,
nonce: userOp.nonce,
sender: userOp.sender
}, {
strategy_code: userOp.strategyCode
}]
})
}

export const getAccount = (network = 'ethereum'): Promise<| any> => {
return axios.post('/api/v1/paymaster', {
"jsonrpc": "2.0",
"id": axiosIndex++,
"method": "pm_paymasterAccount",
"params": [network]
})
}

0 comments on commit 5253104

Please sign in to comment.