3

Inside geth how could I convert abi object into a string? I want to convert it into string to apply str.replace(/[\r\n]/g, ''); to remove new lines and make it more compact.

myContractCompiled.Array.info.abiDefinition

returns the abi of the contract as:

[{
    constant: true,
    inputs: [{
        name: "id",
        type: "string"
    }, {
        name: "index",
        type: "uint256"
    }],
    name: "get_length",
    outputs: [{
        name: "",
        type: "uint256"
    }],
    payable: false,
    type: "function"
}, 
...
{
    inputs: [],
    payable: false,
    type: "constructor"
}]

But I am facing with following error when I try to convert abi object into string:

> myContractCompiled.Array.info.abiDefinition.toString()
"[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]"

Thank you for your valuable time and help.

5
> JSON.stringify(myContractCompiled.Array.info.abiDefinition)
"[{\"constant\":true,\"inputs\":[],\"name\":\"test_callstack\",\"outputs\":[{\"name\":\"\",\"type\":\"int256\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[],\"name\":\"ownerOnly\",\"outputs\":[],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"owner\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"transferOwnership\",\"outputs\":[],\"payable\":false,\"type\":\"function\"},{\"inputs\":[],\"type\":\"constructor\"}]"

See also: JSON.stringify()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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