Bridge | Parameters when deploying

Hello team! :wave:

I am trying to modify the parameters that the smart contract needs to be deployed, but I have some bugs in the Java part.

Here is one of the changes in a simplified way:

Implementing the metadata standard for smart contracts (Contract-level metadata)

Solidity
I will omit the variable declaration and operation. The problem is with the constructor.

constructor(
        string memory uri,
        string memory contractName,
        string memory contractSymbol,
        string memory contractUri,
    ) ERC1155(uri) {
        name = contractName;
        symbol = contractSymbol;
        scUri = contractUri;
    }

Ardor
File: AssetsErc1155Peg.java
Line: 382

if (pegContext.initializationError != null) {
            if (pegContext.initializationError.equals(CONTRACT_ADDRESS_MISSING_ERROR) && DEPLOY_ETH_CONTRACT_COMMAND.equals(command)) {
                return pegContext.deployEthContract(context,
                        getParameter(context, requestParams,"uri"),
                        getParameter(context, requestParams,"name"),
                        getParameter(context, requestParams,"symbol")),
                        getParameter(context, requestParams,"contractUri"));
            } else {
                return context.generateErrorResponse(10004, "Peg initialization error " + pegContext.initializationError);
            }
        }

Line: 1118

private JO deployEthContract(AbstractContractContext context, String uri, String name, String symbol, String contractUri) {
            try {
                BigInteger ethGasPrice = getEthGasPrice();
                ERC1155MintBurn contract =
                        ERC1155MintBurn.deploy(web3j,
                                createTransactionManager(params, ethBlockedAccount, false),
                                new StaticGasProvider(ethGasPrice, DefaultGasProvider.GAS_LIMIT),
                                Convert.nullToEmpty(uri), Convert.nullToEmpty(name), Convert.nullToEmpty(symbol), Convert.nullToEmpty(contractUri)).send();
                JO response = new JO();
                response.put("ethContractAddress", contract.getContractAddress());
                return response;
            } catch (Exception e) {
                Logger.logErrorMessage("Exception while deploying", e);
                return context.generateErrorResponse(10500, "" + e);
            }
        }

The error I have when deploying the contract, with deployEthContract is the following:
"errorDescription": "java.lang.NoSuchMethodError: 'org.web3j.protocol.core.RemoteCall com.jelurida.web3j.generated.ERC1155MintBurn.deploy(org.web3j.protocol.Web3j, org.web3j.tx.TransactionManager, org.web3j.tx.gas.ContractGasProvider, java.lang.String, java.lang.String, java.lang.String, java.lang.String)'",

Java and Solidity code compiles perfectly. The contract is deployed in Ardor is deployed as well.

The problem is only when using deployEthContract

Thank you!

So you are adding a contractUri parameter to the constructor but the Java wrapper is not updated. Try to call the generateContractWrappers gradle task manually. Unfortunately, due to the limits of the Ardor contract size, significant portion of the contract code, together with the generated wrappers must be deployed as a library - erc1155-0.0.1.jar. So first check if the wrappers were correctly generated and the method com.jelurida.web3j.generated.ERC1155MintBurn.deploy which is in erc1155-0.0.1.jar has the correct parameters. Then make sure the ardor contract executes with this library in class path and not some old one.

It seems that if the parameters are updated... another place to look?

public static RemoteCall<ERC1155MintBurn> deploy(Web3j web3j, Credentials credentials, ContractGasProvider contractGasProvider, String uri, String contractName, String contractSymbol, String contractUri) {
        String encodedConstructor = FunctionEncoder.encodeConstructor(Arrays.<Type>asList(new org.web3j.abi.datatypes.Utf8String(uri), 
                new org.web3j.abi.datatypes.Utf8String(contractName), 
                new org.web3j.abi.datatypes.Utf8String(contractSymbol), 
                new org.web3j.abi.datatypes.Utf8String(contractUri)));
        return deployRemoteCall(ERC1155MintBurn.class, web3j, credentials, contractGasProvider, BINARY, encodedConstructor);
    }

    public static RemoteCall<ERC1155MintBurn> deploy(Web3j web3j, TransactionManager transactionManager, ContractGasProvider contractGasProvider, String uri, String contractName, String contractSymbol, String contractUri) {
        String encodedConstructor = FunctionEncoder.encodeConstructor(Arrays.<Type>asList(new org.web3j.abi.datatypes.Utf8String(uri), 
                new org.web3j.abi.datatypes.Utf8String(contractName), 
                new org.web3j.abi.datatypes.Utf8String(contractSymbol), 
                new org.web3j.abi.datatypes.Utf8String(contractUri)));
        return deployRemoteCall(ERC1155MintBurn.class, web3j, transactionManager, contractGasProvider, BINARY, encodedConstructor);
    }

To get that java.lang.NoSuchMethodError, the ERC1155MintBurn.class in erc1155-0.0.1.jar is not compiled from the code you pasted. Check why. Maybe you didn't copy the new version to the lib directory of the Ardor installation, or you didn't restart the Ardor node. Not sure.

1 Like

I forgot to try the number one solution for all IT people... reboot! :sweat_smile: :rofl:

Now its working, thanks!!!

1 Like