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
I'm encountering an "invalid opcode" error with my Ethereum smart contract. While deployment and getNumber calls work, setName results in an error. Here are the details:
Solidity Contract:
pragma solidity^0.8.19;
contractConstruct {
uint256private number;
stringprivate name;
constructor(uint256_number) {
number = _number;
}
function getNumber() publicviewreturns (uint256) {
return number;
}
function setNumber(uint256_number) public {
number = _number;
}
function getName() publicviewreturns (stringmemory) {
return name;
}
function setName(stringmemory_name) public {
name = _name;
}
}
Ruby Script:
require'eth'require'forwardable'client=Eth::Client.create('http://127.0.0.1:8545')contract_address="0x459E0a953e6fAe85b248017b7c4484500b08F57C"contract=Eth::Contract.from_file(file: '../contracts/construct.sol')tester_contract=Eth::Contract.from_abi(name: "Construct",address: contract_address,abi: contract.abi)deployer_account=Eth::Key.new(priv: '0xc1f3f4d9fd9a7fe90b966825a780697a400c675e56f9153ed21bc045c0e7207e')puts"Deployer account balance: #{client.eth_get_balance(deployer_account.address)['result'].to_i(16) / 1e18} ETH"client.max_fee_per_gas=41_000_000_000client.max_priority_fee_per_gas=4_000_000_000# Call the getNumber functionbeginresponse=client.call(tester_contract,"getNumber")puts"Current number: #{response}"rescueStandardError=>eputs"Error while getting number: #{e.message}"putse.backtraceend# Call the setNumber functionbeginresponse=client.transact_and_wait(tester_contract,"setNumber",12345,sender_key: deployer_account,gas_limit: 10_000_000)puts"Transaction hash for setNumber: #{response}"rescueStandardError=>eputs"Error while calling setNumber: #{e.message}"putse.backtraceend# Call the setName functionbeginresponse=client.transact_and_wait(tester_contract,"setName","huy",sender_key: deployer_account,gas_limit: 10_000_000)puts"Transaction hash for setName: #{response}"rescueStandardError=>eputs"Error while calling setName: #{e.message}"putse.backtraceend# Call the getName functionbeginresponse=client.call(tester_contract,"getName")puts"Current name: #{response}"rescueStandardError=>eputs"Error while getting name: #{e.message}"putse.backtraceend
Additional Context:
The number works fine, indicating the contract is deployed correctly.
The "invalid opcode" error suggests the issue might be with the setName or getName functions or how strings are being handled.
Any help or guidance would be greatly appreciated!
The text was updated successfully, but these errors were encountered:
I'm encountering an "invalid opcode" error with my Ethereum smart contract. While deployment and
getNumber
calls work,setName
results in an error. Here are the details:Solidity Contract:
Ruby Script:
Additional Context:
setName
orgetName
functions or how strings are being handled.Any help or guidance would be greatly appreciated!
The text was updated successfully, but these errors were encountered: