You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First, forgive my terminology, I am very new to web-anything.
In short, I have a website where users can login using their tokens, solve some puzzles and upgrade their tokens by changing a stat when they solve the puzzles.
The upgrade function is ownerOnly on my contract, so I am using my private key in my js to create a wallet and when a condition is met, to sign a transaction with.
My transactions keep failing with the message: " Warning! Error encountered during contract execution [execution reverted] " on etherscan.
I have looked in these discussions and elsewhere too which helped me iron out some of the errors, but this is where I am stuck :) I left some comments to show what I have tried so far. so excuse the potential redundancies in there, just not sure if they are really redundant.
async function handleThings(){
if(window.ethereum){
const provider = new ethers.providers.Web3Provider(window.ethereum); //rinkeby
const user = provider.getSigner(); //won't really sign anything actually, since they don't have the priv on the contract unless owner
const userAddress = user.getAddress();
const authprovider = new ethers.providers.EtherscanProvider("rinkeby"); //do I even need a 2nd provider? Just connecting to provider also didn't work
const usercontract = new ethers.Contract(cur_address, cur.abi, user);
const authwallet = new ethers.Wallet(process.env.REACT_APP_PRIVATE_KEY, provider);
const authcontract = new ethers.Contract(cur_address, cur.abi, authwallet); //do I need a 2nd contract instance? I think not, but same errors regardless.
try{
//where I get the owned tokens. works fine.
const tokens = await usercontract.balanceOf(userAddress);
const tokenIDs = await usercontract.getOwnerTokenIds(userAddress);
/* making sure we are on the same network, we are.
console.log(user.provider);
console.log(authwallet.provider);
*/
var txpromise = authcontract.populateTransaction.upgradeToken(tokenIDs[0],{gasLimit:100000});
//txpromise.wait(); /not a function error
console.log(txpromise); //logs it, no errors
var send = authwallet.sendTransaction(txpromise);
send.then(function(txpromise){console.log(txpromise);});
}catch(err){
console.log("error: ", err); //no errors, fails on etherscan
}
}
}
The method I am calling works fine if I just call it with my function btw, so upgradeToken() definitely works when signed with my wallet (if I am the user and just sign my own contract) and errors out on user's. Just trying to make sure it can work automatically, using my wallet, so I don't have to go and check user's logs to see who gets an upgrade everyday manually 😆
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
First, forgive my terminology, I am very new to web-anything.
In short, I have a website where users can login using their tokens, solve some puzzles and upgrade their tokens by changing a stat when they solve the puzzles.
The upgrade function is ownerOnly on my contract, so I am using my private key in my js to create a wallet and when a condition is met, to sign a transaction with.
My transactions keep failing with the message: " Warning! Error encountered during contract execution [execution reverted] " on etherscan.
I have looked in these discussions and elsewhere too which helped me iron out some of the errors, but this is where I am stuck :) I left some comments to show what I have tried so far. so excuse the potential redundancies in there, just not sure if they are really redundant.
The method I am calling works fine if I just call it with my function btw, so upgradeToken() definitely works when signed with my wallet (if I am the user and just sign my own contract) and errors out on user's. Just trying to make sure it can work automatically, using my wallet, so I don't have to go and check user's logs to see who gets an upgrade everyday manually 😆
Many thanks in advance.
Beta Was this translation helpful? Give feedback.
All reactions