HomeGuidesAPI ReferenceChangelog
GuidesAPI ReferenceCommunityDiscordBlogFAQBug BountyAnnouncementsChange Log
Guides

Deploying a Smart Contract

trident-java allows you to deploy a smart contract by ABI and bytecode.

Compile the Smart Contract

Compilation to bytecode is performed by the Solidity compiler, solc.

To compile the Solidity code run:

$ solc <contract>.sol --bin --abi --optimize -o <output-dir>/

The --bin and --abi compiler arguments are both required to deploy your smart contract with Trident-Java.

Deploy the Smart Contract

The smart contract is being ready to be deployed with the compiled ABI and bytecode:

ApiWrapper wrapper = ApiWrapper.ofMainnet("hex private key");
String byteCode = "bytecode";
String abi = "ABI";
Contract cntr = new Contract.Builder()
                        .setOwnerAddr(c.parseAddress("address"))
                        .setOriginAddr(c.parseAddress("address"))                
     .setBytecode(ByteString.copyFrom(Numeric.hexStringToByteArray(bytecode)))
                                    .setAbi(abi)
                                    // .setCallValue()
                                    // .setName()
                                    // .setConsumeUserResourcePercent()
                                    // .setOriginEnergyLimit()
                                    .build();
cntr.setWrapper(c);
TransactionBuilder builder = cntr.deploy();

trident-java will return the transaction hash after a successful broadcast.