Eip838ExecutionError: execution reverted: Ownable: caller is not the owner

405 views Asked by At

sending transaction, error occured.

Eip838ExecutionError: execution reverted: Ownable: caller is not the owner

innerError: [Eip838ExecutionError: execution reverted: Ownable: caller is not the owner] { innerError: undefined, code: 3, receipt: undefined, data: '' }, code: 310, receipt: undefined }

I don't know why this error occur. I deployed erc1155 with ownerble, mintable, burnable. when i read property 'owner', it was my EOA address.

i signed my private key, then i sendTransaction. its ok about sending testEth.

help me plese

my contract code here,

// 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);
    }
}

my code for compile here

// 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);

in here, problem occured.

// 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();

I sended Transaction with my privatekey sign.

I called function mint with ownable. it is required that owner() = msg.sender. but I deployed this contract, I am owner of this contract. and I checked with Etherscan about owner().

but error occured.

0

There are 0 answers