0

I have a smart contract. I own, it belongs to my wallet. I am trying to implement a function to transfer the OWNERSHIP of this smart contract to another wallet. I have two solutions, but for some reason both give an error. The first option that gives an error: "GAS IS MISSING" p.s. Both wallets have enough funds for a transaction!!! Smart contracts have not expired yet, I am the owner

async function transactionContract() {

  /* This is the owner of the contract */
  let signerAddress = gettingOwnerByKey(
    "private key"
  ).address;

  /* This is the wallet address to which I want to transfer ownership of this contract */
  let addressRecipient = "0x82A8AD5c429903c082686a307083330F99c40E53";

/*This is the contract itself that I want to transfer */
  const escrow = new web3.eth.Contract(
    ABI2,
    "0xF36198Ce8Dfe6A5694541bb1604195A7b9E2A61D"
  );
  const NET_ID = "35855456";
  
  /*This is a transaction object */
   /*shifting(addressRecipient) - This is the method by which the smart contract is transferred*/
  
  let tx = await escrow.methods.shifting(addressRecipient).encodeABI({
    chainId: NET_ID,
    nonce:  await web3.eth.getTransactionCount(signerAddress, "pending"),
    gasPrice: web3.utils.toWei("42", "gwei"),
    gas: "320000",
  });
 

  /*This is me signing the transaction with the private key*/

  const signedContract = await web3.eth.accounts.signTransaction(
    tx,
    "private key"
  ).then(console.log);
 
  /*This is me sending the signed transaction to the network*/

  const transactionSignature = await web3.eth.sendSignedTransaction(
    signedContract.rawTransaction
  )
  console.log(transactionSignature)
  
 
}

transactionContract()

I have a second solution, it creates a transaction, but returns it not executed. Error: "Transaction has been reverted by the EVM:"

Uncaught (in promise) Error: Transaction has been reverted by the EVM:
{
  "blockHash": "0x2916cfd3967874dd4a874f19800da1729200c98b10b773a645f43f20d84adc0d",
  "blockNumber": 6626284,
  "contractAddress": null,
  "cumulativeGasUsed": 23386,
  "from": "0x061a96c2b5a18b132783bf65a45bc720e6c95b2a",
  "gasUsed": 23386,
  "logs": [],
  "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
  "status": false,
  "to": "0xf36198ce8dfe6a5694541bb1604195a7b9e2a61d",
  "transactionHash": "0x6b5da5768a926f4f0702047a4b46beabc3c07686174e69b38a0b876b45195a22",
  "transactionIndex": 0
}
    at Object.TransactionError (errors.js?490f:87)
    at Object.TransactionRevertedWithoutReasonError (errors.js?490f:98)
    at eval (index.js?7789:394)

Here is the code that results in the above error:

async function transaction(){

/* This is the owner of the contract */
let signerAddress = gettingOwnerByKey(
  "private key"
).address;

 /* This is the wallet address to which I want to transfer ownership of this contract */
let addressRecipient = "0x82A8AD5c429903c082686a307083330F99c40E53";

/*This is the contract itself that I want to transfer */
const recipient = new web3.eth.Contract(
  ABI2,
  "0xF36198Ce8Dfe6A5694541bb1604195A7b9E2A61D"
);

const nonce = await web3.eth.getTransactionCount(signerAddress, "pending");
const data = recipient.methods.shifting(addressRecipient).encodeABI();

const txData = {
    chainId: web3.utils.toHex('35855456'),
    nonce,
    from: signerAddress,
    gasPrice: web3.utils.toWei("42", "gwei"),
    gas: web3.utils.toHex('320000'),
    to: recipient.options.address,
    value: '0x',
    data
};

const tx = await web3.eth.accounts.signTransaction(txData, "private key");
await web3.eth.sendSignedTransaction(tx.rawTransaction);
const callTransaction = await recipient.methods.id().call();
console.log(callTransaction);
}

transaction()

My smart contract code

Payment: event({amount: uint256(wei), arg2: address})
Shifting: event({old_beneficiary: address, new_beneficiary: address})

# public variables 
deadline: public(timestamp)
beneficiary: public(address)

# private variables
@public
def __init__(_beneficiary: address, _duration: timedelta):
    self.beneficiary = _beneficiary 
    self.deadline = block.timestamp + _duration

@public
@payable
def __default__():
    log.Payment(msg.value, msg.sender)
    pass

@public

def shifting(new_beneficiary: address):
    assert msg.sender == self.beneficiary, "sender is owners"
    assert block.timestamp < self.deadline, "not deadline"
    log.Shifting(self.beneficiary, new_beneficiary)
    self.beneficiary = new_beneficiary

@public

def finalize():
    assert msg.sender == self.beneficiary, "sender is owners"
    assert self.balance > 0, "invalid balance"
    assert block.timestamp > self.deadline, "not deadline"
    selfdestruct(self.beneficiary)

@public
@constant
def cash() -> wei_value:
    return self.balance

I would be very grateful for your help! Thank you in advance!

21
  • What is shifting??? – goodvibration Jan 11 at 9:28
  • Also, change let tx = await escrow.methods.shifting(addressRecipient).encodeABI({ to: – goodvibration Jan 11 at 9:30
  • let tx = {data: escrow.methods.shifting(addressRecipient).encodeABI(), – goodvibration Jan 11 at 9:31
  • shifting is a custom method for transferring ownership of a smart contract. The parameter takes the address of the wallet to which the smart contract will belong after the transaction – Artem Strekalov Jan 11 at 9:37
  • I tried to do as you say. The result was the same. – Artem Strekalov Jan 11 at 9:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.