-
Notifications
You must be signed in to change notification settings - Fork 9
Open
Description
What I do
Calling a simple "name" function on my smartcontract, which is a pure function that returns a string.
The abi of this function:
# config/web3.yml
contract_abi = "[{\"inputs\":[],\"name\":\"name\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"}]"More readable version:
[{"inputs"=>[],
"name"=>"name",
"outputs"=>[{"internalType"=>"string", "name"=>"", "type"=>"string"}],
"stateMutability"=>"view",
"type"=>"function"}]The error
When calling the function, I got the following error:
RuntimeError:
Function name is not constant: name, requires to sign transactionI'm surprised that the lib asks for a signature, whereas - AFAIK - pure functions are not supposed to require signature, right? 🤔
My code
class ContractService
def initialize
contract_address = "0x..."
provider = Web3::Eth::Rpc.new(
host: infura_url,
port: 443,
connect_options: {
open_timeout: 200,
read_timeout: 1400,
use_ssl: true,
rpc_path: "/v3/#{Rails.configuration.web3['infura_project_id']}"
}
)
contract_abi = Rails.configuration.web3["contract_abi"]
contract_factory = provider.eth.contract(contract_abi)
@contract_instance = contract_factory.at(contract_address)
end
def name
result = @contract_instance.name
puts result
end
end# Function call
ContractService.new.nameReactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels