I'm trying to set a message to my Contract setmsg through a proxy contract using delegatecall.Using hardhat.
getting this error:
error: {
code: -32603,
message: "Error: VM Exception while processing transaction: reverted with reason string 'delegate failed'",
data: {
message: "Error: VM Exception while processing transaction: reverted with reason string 'delegate failed'",
txHash: '0x61cbb5af804b22f21431f6e577db17bc677ee595af1f509bf769dfa63c8d5d2a',
data: '0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f64656c6567617465206661696c65640000000000000000000000000000000000'
}
},
payload: {
method: 'eth_sendRawTransaction',
params: [
'0x02f8f5827a6982029d843b9aca0085010f68944a830927c09493b800cd7acdca13754624d4b1a2760a86be0d1f0ab884c0ed254b000000000000000000000000bd2fe040d03eb1d1e5a151fbcc19a033332230190000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000a6d65737361676573657400000000000000000000000000000000000000000000c001a08f5f604aac553f6552189763af2d6c5d06c6dc1a9509d68e68fa29ef0c7021e6a023883eb83df0b38d207d7e8b1f3a0f524d5de7200520b4b973844842b5f3363b'
],
id: 9,
jsonrpc: '2.0'
},
shortMessage: 'could not coalesce error'
Contract to set the message
pragma solidity ^0.8.0;
contract setmsg{
constructor (){
}
string public message = "no message";
function setmessage ( string calldata _msg ) external payable{
message =_msg;
}
function viewvalue ()public view returns(string memory mensaje){
mensaje=message;
}
}
Proxy contract
pragma solidity ^0.8.0;
contract proxymsg{
constructor (){
}
function setproxy (address _original, string calldata _msg ) external payable{
(bool success, bytes memory data) =_original.delegatecall(abi.encodeWithSignature("setmessage(string calldata)", _msg));
require (success, "delegate failed");
}
}
js script to send transaction (hardcoded contract addresses)
async function main() {
const provider = new hre.ethers.getDefaultProvider("http://localhost:8545/");
const signer = new hre.ethers.Wallet("0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80", provider);
const msj = new hre.ethers.Contract("0x93B800CD7ACdcA13754624D4B1A2760A86bE0D1f", abi4, signer);
const origin = new hre.ethers.Contract("0xBD2fe040D03EB1d1E5A151fbcc19A03333223019", abi3, signer);
balance = await msj.setproxy("0xBD2fe040D03EB1d1E5A151fbcc19A03333223019","messageset", {value: 10, gasLimit: 600000});
console.log(balance);
console.log(changed);
balance2 = await origin.viewvalue();
console.log(balance2);
}
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});