0

I have created an smart contract but the code in the sol file have disappeared. But the jeson file still remains. Can I generate my smartcontract again from ABI ?

bumped to the homepage by Community 2 days ago

This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.

0

You can't.

The ABI is not the full contract, it doesn't know what exactly each function does. Consider these simple contracts:

contract Test {
    uint public num;

    function setNum(uint myNum) public {
        num = myNum;
    }
}

And

contract Test {
    uint public num;

    function setNum(uint myNum) public {
        //do nothing;
    }
}

They both have the very same ABI:

[{
    "constant": true,
    "inputs": [],
    "name": "num",
    "outputs": [{
        "name": "",
        "type": "uint256"
    }],
    "payable": false,
    "stateMutability": "view",
    "type": "function"
}, {
    "constant": false,
    "inputs": [{
        "name": "myNum",
        "type": "uint256"
    }],
    "name": "setNum",
    "outputs": [],
    "payable": false,
    "stateMutability": "nonpayable",
    "type": "function"
}]

Note that the ABI is just an interface, so it only cares about the "form" of things. It cares about which functions exist and what are their types and parameters; whether they return values or not; what are the public variables and constants, and so on.

Sorry you lost your contract, but it's impossible to generate it from its ABI.

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.