Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please add installing contract examples #159

Open
Jiuhong-casperlabs opened this issue Jan 12, 2023 · 1 comment
Open

Please add installing contract examples #159

Jiuhong-casperlabs opened this issue Jan 12, 2023 · 1 comment
Labels
documentation Improvements or additions to documentation

Comments

@Jiuhong-casperlabs
Copy link

Hello,

When installing contract I have java.nio.BufferOverflowException issue while it worked fine on previous version.
Can you add a such example please?

Thank you.

@Jiuhong-casperlabs Jiuhong-casperlabs added the documentation Improvements or additions to documentation label Jan 12, 2023
@Jiuhong-casperlabs
Copy link
Author

Jiuhong-casperlabs commented Jan 13, 2023

Delegation has the same error java.nio.BufferOverflowException. Here is the code

package com.jh;

import java.io.File;
import java.io.InputStream;

import com.casper.sdk.helper.CasperValidatorHelper;
import com.casper.sdk.model.deploy.Deploy;
import com.casper.sdk.model.deploy.DeployResult;
import com.casper.sdk.model.key.PublicKey;
import com.casper.sdk.service.CasperService;
import com.syntifi.crypto.key.Ed25519PrivateKey;

import java.math.BigInteger;

public class TestDelegate {
    public static void main(String args[]) {
        Ed25519PrivateKey from = new Ed25519PrivateKey();
        try {
            // from
            File f = new File("/home/jh/keys/test1/secret_key.pem");
            String frompath = f.getPath();
            from.readPrivateKey(frompath);

            // validator public key
            PublicKey validator = PublicKey
                    .fromTaggedHexString("0109b48a169e6163078a07b6248f330133236c6e390fe915813c187c3f268c213e");
            // delegator public key
            PublicKey delegator = PublicKey
                    .fromTaggedHexString("0193b3800386aefe11648150f6779158f2c7e1233c8e9b423338eb71b93ae6c5a9");
            // wasm file
            String filePath = "wasm/contract.wasm";
            InputStream contractwasmIn = HowToUtils.getWasmIn(filePath);

            System.out.println("contractwasmIn=>" + contractwasmIn);
            byte[] wasmBytes = HowToUtils.readWasm(contractwasmIn);
            // build deploy
            Deploy deploy = CasperValidatorHelper.createValidatorDelegation(from, wasmBytes,
                    BigInteger.valueOf(2500000000L), validator, delegator, "casper-test");
            // send deploy
            final CasperService casperService = CasperService.usingPeer("94.130.10.55",
                    7777);
            DeployResult deployResult = casperService.putDeploy(deploy);
            // deploy hash
            System.out.println(deployResult.getDeployHash());
        } catch (Exception e) {
            System.out.println("err");
            System.out.println(e);
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

1 participant