0

So I have a basic function call in Solidity that returns a string

function getString() constant returns (string) {
  return "hello";
}

I call it using web3 after instantiating the contract

const Contract = new web3.eth.Contract(abi, contractAddress, {
  from: applicationAccount.address,
  gasPrice: '20000000',
  gas: 4711489
});

async function getString() {
  let hash = await Contract.methods.getString.call()
  return hash;
}

The object returned is a large object describing the contract, when all I want returned is the string hello

{ call: { [Function: bound _executeMethod] request: [Function: bound _executeMethod] },
send: { [Function: bound _executeMethod] request: [Function: bound _executeMethod] },
encodeABI: [Function: bound _encodeMethodABI],
estimateGas: [Function: bound _executeMethod],
arguments: [],
_method:
 { constant: true,
 inputs: [],
 name: 'getString',
 outputs: [ [Object] ],
 payable: false,
 stateMutability: 'view',
 type: 'function',
 signature: '0xb96d1702' },

How can I return the string hello?

1 Answer 1

1

You should use

await Contract.methods.getString().call()
1
  • this ends up returning undefined Commented Jul 26, 2018 at 18:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.