我正在使用 Infura,我想使用 web3 创建一个事务,但是我遇到了一个错误。
这是我的交易执行代码:
async approve(marketAddress, tokenId){
const abi = store.state.contract.nftAbi;
const provider = new Web3.providers.HttpProvider(process.env.VUE_APP_INFURA_NETWORK);
const web3 = new Web3(provider);
const contract_Address = process.env.VUE_APP_INFURA_NFT_CONTRACT;
const nft = new web3.eth.Contract(abi, contract_Address);
const deployer = process.env.VUE_APP_DEPLOYER_ADDRESS;
const privateKey = process.env.VUE_APP_DEPLOYER_PRIVATE_KEY.replace('0x','');
let block = await web3.eth.getBlock("latest");
let gasLimit = Math.ceil((block.gasLimit/block.transactions.length))
const tx = {
nonce: web3.eth.getTransactionCount(deployer),
from: deployer,
to: contract_Address,
gasLimit: web3.utils.toHex(gasLimit),
gas:web3.utils.toHex(await web3.eth.getGasPrice()),
value: web3.utils.toHex('0'),
data: nft.methods.approve(marketAddress, tokenId).encodeABI()
}
const signature = await web3.eth.accounts.signTransaction(tx, privateKey)
await web3.eth.sendSignedTransaction(signature.rawTransaction).on(
"receipt",async()=>{}
)
}
这是我收到的错误:
processing response error (body="{\"jsonrpc\":\"2.0\",\"id\":103,\"error\":{\"code\":-32601,\"message\":\"The method eth_sendTransaction does not exist/is not available\"}}", error={"code":-32601}, requestBody="{\"method\":\"eth_sendTransaction\",\"params\":[{\"gas\":\"0x2cd60\",\"value\":\"0x3782dace9d90000\",\"from\":\"0x0979d47351933bbfea0891c6cb94748b6d975aa5\",\"to\":\"0x8d17b0c4924cc1ab42ac4ba4dbb20dbe2e97a78c\",\"data\":\"0x243adbdd0000000000000000000000000000000000000000000000000000000000000001\"}],\"id\":103,\"jsonrpc\":\"2.0\"}", requestMethod="POST", url="https://sepolia.infura.io/v3/4d7d800d984c4d4f83e2fe1a5fcf1245", code=SERVER_ERROR, version=web/5.7.1)
at p.makeError (index.ts:269:28)
at p.throwError (index.ts:281:20)
at index.ts:341:28
at Generator.next (<anonymous>)
at o (chunk-vendors.f2ce1fb5.js:2:470559)
为什么会出现此错误,我该如何解决?