100 lines
2.4 KiB
TypeScript
100 lines
2.4 KiB
TypeScript
import axios from 'axios'
|
|
|
|
const ADD_TASK_URI = '/chain/req'
|
|
|
|
const GAS_PRICE_URI = '/chain/estimate_gas'
|
|
|
|
export async function pushTaskToChain(data) {
|
|
let url = `${process.env.CHAIN_CLIENT_URL}${ADD_TASK_URI}`
|
|
let reqConfig: any = {
|
|
method: 'post',
|
|
url,
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
data: JSON.stringify(data),
|
|
}
|
|
return axios(reqConfig)
|
|
}
|
|
|
|
export async function fetchGasPrice(data) {
|
|
let url = `${process.env.CHAIN_CLIENT_URL}${GAS_PRICE_URI}`
|
|
let reqConfig: any = {
|
|
method: 'post',
|
|
url,
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
data: JSON.stringify(data),
|
|
}
|
|
return axios(reqConfig)
|
|
}
|
|
/**
|
|
success: {
|
|
"jsonrpc": "2.0",
|
|
"id": 1,
|
|
"result": "0x77b49"
|
|
}
|
|
error: {
|
|
"error": {
|
|
"code": 3,
|
|
"data": "0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001d45524332303a20696e73756666696369656e7420616c6c6f77616e6365000000",
|
|
"message": "execution reverted: ERC20: insufficient allowance"
|
|
},
|
|
"id": 1,
|
|
"jsonrpc": "2.0"
|
|
}
|
|
*/
|
|
export async function erc20TransferGas() {
|
|
let url = process.env.CHAIN_RPC_URL
|
|
let address = process.env.CHAIN_CEG_ADDRESS
|
|
let walletAddress = process.env.CHAIN_WALLET_ADDRESS
|
|
let reqData = {
|
|
jsonrpc: '2.0',
|
|
id: 1,
|
|
method: 'eth_estimateGas',
|
|
params: [
|
|
{
|
|
data: '0x23b872dd0000000000000000000000009c257b7830566e889cd2eef906541f130d4a75f600000000000000000000000042448c6a38c08637218d8327b748f213fc2c02310000000000000000000000000000000000000000000000000000000000000000',
|
|
from: walletAddress,
|
|
to: address,
|
|
},
|
|
],
|
|
}
|
|
let reqConfig: any = {
|
|
method: 'post',
|
|
url,
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
data: JSON.stringify(reqData),
|
|
}
|
|
return axios(reqConfig)
|
|
}
|
|
|
|
export async function ethTransferGas() {
|
|
let url = process.env.CHAIN_RPC_URL
|
|
let walletAddress = process.env.CHAIN_WALLET_ADDRESS
|
|
let reqData = {
|
|
jsonrpc: '2.0',
|
|
id: 1,
|
|
method: 'eth_estimateGas',
|
|
params: [
|
|
{
|
|
from: walletAddress,
|
|
to: walletAddress,
|
|
value: '0x0',
|
|
},
|
|
],
|
|
}
|
|
let reqConfig: any = {
|
|
method: 'post',
|
|
url,
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
data: JSON.stringify(reqData),
|
|
}
|
|
return axios(reqConfig)
|
|
}
|