Eip838ExecutionError:执行已恢复:可拥有:调用者不是所有者

问题描述 投票:0回答:1

发送交易,发生错误。

Eip838ExecutionError:执行已恢复:可拥有:调用者不是所有者

innerError:[Eip838ExecutionError:执行已恢复:可拥有:调用者不是所有者] { 内部错误:未定义, 代码:3, 收据:未定义, 数据: '' }, 代码:310, 收据:未定义 }

我不知道为什么会出现这个错误。我部署了erc1155与ownerble、mintable、burnable。 当我读到房产“所有者”时,这是我的 EOA 地址。

我签署了我的私钥,然后我发送交易。发送 testEth 就可以了。

请帮助我

我的合约代码在这里,

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
import "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Burnable.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract DTicket is ERC1155, ERC1155Burnable, Ownable {
    constructor(address initialOwner) ERC1155("") Ownable(initialOwner) {}

    function mint(address account, uint256 id, uint256 amount, bytes memory data)
        public
        onlyOwner
    {
        _mint(account, id, amount, data);
    }

    function mintBatch(address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data)
        public
        onlyOwner
    {
        _mintBatch(to, ids, amounts, data);
    }
}

我的编译代码在这里

// This code will compile smart contract and generate its ABI and bytecode
// Alternatively, you can use something like `npm i solc && npx solcjs MyContract.sol --bin --abi`


const solc = require('solc');
const path = require('path');
const fs = require('fs');


const fileName = 'DTicket.sol';
const contractName = 'DTicket';

// Read the Solidity source code from the file system
const contractPath = path.join(__dirname, fileName);
const sourceCode = fs.readFileSync(contractPath, 'utf8');

// solc compiler config
const input = {
    language: 'Solidity',
    sources: {
        [fileName]: {
            content: sourceCode,
        },
    },
    settings: {
        outputSelection: {
            '*': {
                '*': ['*'],
            },
        },
    },
};

// Compile the Solidity code using solc
const compiledCode = JSON.parse(solc.compile(JSON.stringify(input)));
//console.log(compiledCode);
// Get the bytecode from the compiled contract
const bytecode = compiledCode.contracts[fileName][contractName].evm.bytecode.object;

// Write the bytecode to a new file
const bytecodePath = path.join(__dirname, 'DTicketBytecode.bin');
fs.writeFileSync(bytecodePath, bytecode);

// Log the compiled contract code to the console
console.log('Contract Bytecode:\n', bytecode);

// Get the ABI from the compiled contract
const abi = compiledCode.contracts[fileName][contractName].abi;

// Write the Contract ABI to a new file
const abiPath = path.join(__dirname, 'DTicketAbi.json');
fs.writeFileSync(abiPath, JSON.stringify(abi, null, '\t'));

// Log the Contract ABI to the console
console.log('Contract ABI:\n', abi);

在这里,出现问题了。

// First step: initialize `web3` instance
const {Web3} = require('web3');
const { ETH_DATA_FORMAT, DEFAULT_RETURN_FORMAT } = require('web3');
const fs = require('fs');
const path = require('path');


require("dotenv").config();
// Set up a connection to the Ethereum network
const network = process.env.ETHEREUM_NETWORK;
  const web3 = new Web3(
    new Web3.providers.HttpProvider(
      `https://${network}.infura.io/v3/${process.env.INFURA_API_KEY}`,
    ),
  );







const sendTx = async () => {
  //const myContract = new web3.eth.Contract()
  const accountFrom = {
    privateKey: process.env.SIGNER_PRIVATE_KEY,
    address: process.env.SIGNER_ADDRESS
  };
  

  // 4. Create Contract Instance
  const abi = require('./DTicketAbi.json');
  const contractor = new web3.eth.Contract(abi, process.env.CONTRACT_ADDRESS);
  var mintAccount = accountFrom.address;
  var mintId = 0;
  var mintAmount = 100;
  var mintData = web3.utils.utf8ToHex('1');
  const mint = contractor.methods.mint(mintAccount, mintId, mintAmount, mintData);


  console.log(`Calling the reset function in contract at address: ${process.env.CONTRACT_ADDRESS}`);

  await web3.eth
    .estimateGas(
      {
        from: accountFrom.address,
        to: process.env.CONTRACT_ADDRESS,
        data: mint.encodeABI()
      },
      "latest",
      ETH_DATA_FORMAT,
    )
    .then((value) => {
      limit = value;
    });

  // 7. Sign tx with PK
  const createTransaction = await web3.eth.accounts.signTransaction(
    {
      to: process.env.CONTRACT_ADDRESS,
      data: mint.encodeABI(),
      value: '0x0',
      //value: web3.utils.toWei('0.1', 'ether'),
      //gas: web3.utils.toWei('3', 'gwei'),
      nonce: await web3.eth.getTransactionCount(accountFrom.address),
      maxPriorityFeePerGas: web3.utils.toWei("3", "gwei"),
      maxFeePerGas: web3.utils.toWei("3", "gwei"),
    
    },
    accountFrom.privateKey
  );
   // 8. Send tx and wait for receipt
   const createReceipt = await web3.eth.sendSignedTransaction(createTransaction.rawTransaction);
   console.log(`Tx successful with hash: ${createReceipt.transactionHash}`);
};












async function interact() {

  web3.eth.Contract.handleRevert = true;

  // Read the contract address from the file system
  const deployedAddressPath = path.join(__dirname, 'DTicketAddress.bin');
  const deployedAddress = fs.readFileSync(deployedAddressPath, 'utf8');
  // Create a new contract object using the ABI and bytecode
  const abi = require('./DTicketAbi.json');
  const contract = new web3.eth.Contract(abi, deployedAddress);
  const account = web3.eth.accounts.wallet.add(process.env.SIGNER_PRIVATE_KEY).get(0);
  const defaultAccount = account.address; //providersAccounts[0];


  try {
      // Get the current value of my number
      const owner = await contract.methods.owner().call();
      console.log('msgSender: ' + JSON.stringify(owner, null, 4));
      
      sendTx();


      
      
  } catch (error) {
      console.error(error);
  }
}

interact();

我用我的私钥签名发送了交易。

我用 ownable 调用了 mint 函数。要求owner() = msg.sender。 但我部署了这份合同,我是这份合同的所有者。我用 Etherscan 检查了有关owner()的信息。

但是发生了错误。

transactions ethereum blockchain contract
1个回答
0
投票

兄弟,我对 webjs 不太熟悉,但在 ethers js 中,在做任何可拥有的事情之前,你添加“.connect(signer)”,我不知道 web3 js,但在 ethers 中,你这样做:

const signer = Private_Key
const tx = await contractor.connect(signer).mint(...);

我认为你可以在项目的这一部分使用以太币并继续使用 web3js。 希望这可以帮助你兄弟。

© www.soinside.com 2019 - 2024. All rights reserved.