Comments (1)
The contract invocation feature is implemented since neow3j version 2.0.0. Check it out for the latest release here.
Anyway, I'm attaching here an example based on neow3j version 2.0.1:
import io.neow3j.contract.ContractInvocation;
import io.neow3j.contract.ContractParameter;
import io.neow3j.protocol.Neow3j;
import io.neow3j.protocol.core.methods.response.InvocationResult;
import io.neow3j.protocol.exceptions.ErrorResponseException;
import io.neow3j.protocol.http.HttpService;
import io.neow3j.transaction.InvocationTransaction;
import io.neow3j.wallet.Account;
import java.io.IOException;
import java.math.BigDecimal;
public class ContractInvocationExample {
public static void main(String[] args) throws IOException, ErrorResponseException {
// Crate a connection to an RPC node.
Neow3j neow3j = Neow3j.build(new HttpService("https://node2.neocompiler.io"));
// The script hash of the deployed contract. In this case it is the name service smart
// contract found at this link
// https://github.com/CityOfZion/python-smart-contract-workshop/blob/master/4-domain.py
String contractScriptHash = "1a70eac53f5882e40dd90f55463cce31a9f72cd4";
// Instantiate your account. It will be the originator of the contract invocation.
Account acct = Account.fromWIF("KxDgvEKzgSBPPfuVfw67oPQBSjidEiqTHURKSDL1R7yGaGYAeYnr").build();
// Fetch the account's balances. This is needed to pay for potential fees in the invocation.
acct.updateAssetBalances(neow3j);
// Build the ContractInvocation according to your needs.
ContractInvocation invoc = new ContractInvocation.Builder(neow3j)
.contractScriptHash(contractScriptHash)
.account(acct)
// Add parameters in the correct order as they are expected by the contract.
.parameter(ContractParameter.string("register"))
.parameter(ContractParameter.array(
ContractParameter.string("neow3j.com"),
ContractParameter.byteArrayFromAddress(acct.getAddress())))
// You can add a network fee for priority. Your account needs to own the GAS for it.
.networkFee(new BigDecimal("0.1"))
.build();
// You can get the invocation transaction object if you for example need to create a custom
// signature from it.
InvocationTransaction tx = invoc.getTransaction();
// If you don't need a special signature, simply let the transaction be signed with the
// account given above.
invoc.sign();
// And finally perform the invocation. The RPC node doesn't inform us about the result of
// the invocation. Therefore this call does not return any information about the call results.
invoc.invoke();
// You can also run a test invocation which gives you the GAS consumption of your invocation
// and the return value that the contract produces when invoked. BUT be careful! If the
// invocation runs trough a CheckWitness() method call in the smart contract it will fail
// and return VM state FAULT. This does not mean that your invocation with invoc.incoke()
// fails. It is just because in this test invoke it is not possible to provide the
// information for completing the witness check.
InvocationResult result = invoc.testInvoke();
}
}
from neow3j.
Related Issues (20)
- Add boilerplate repo for Kotlin backend
- Remove `updatehistory` from `NativeContractState`
- Extend Transaction response object with fields for "signing context"
- Document how to produce a SNAPSHOT HOT 1
- Contract Compiler locking files HOT 15
- Upgrade neo-express version for devpack-test
- Add support for setting `neow3jCompile` gradle task as cacheable or non-cacheable HOT 6
- Fix javadocs HOT 1
- Change bouncycastle provider from bcprov-jdk15on to bcprov-jdk18on
- Move plugin declarations related to the `gradle-plugin` to the `gradle-plugin/build.gradle` file HOT 1
- CI-CD workflow not running when PR is submitted HOT 1
- Is there support to Math.Pow? (Or equivalent) HOT 2
- Compiler is not updating the code / manifest HOT 6
- Prevent integration tests from running in PRs from forks
- Create a tutorial on how to deploy and invoke neow3j-compiled smart contracts using Neo Nova
- Improve documentation of `OracleContract.request()`
- Requirements Documentation of `OracleContract`'s Callback Function
- Neo 3.7.0
- [Neo 3.7.0] Update RPC `getversion` HOT 1
- [Neo 3.7.0] Update config files in int-tests HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from neow3j.