-
Notifications
You must be signed in to change notification settings - Fork 17
How to create a smart contract
Ksenia Slavina edited this page May 27, 2019
·
2 revisions
In order to create a smart contract with the list support, it’s necessary to add the following line of code at the beginning of the smart contract:
import java.util.ArrayList;
private final ArrayList<String> list;
list = new ArrayList<>();
In order to write a list, the standard methods are used for adding the element to an array.
public void addRange(){
for(int i = 0; i < 10000; i++) {
list.add(i + "00000");
}
}
Method which returns the number of lines of an array list
public int count(){
return list.size();
}
Accessing array elements through the index
public String getAt(int i){
return list.get(i);
}
import java.util.ArrayList;
public class Contract extends SmartContract {
private final ArrayList<String> list;
public Contract() {
list = new ArrayList<>();
}
public String hello() {
return "hello";
}
public void addRange(){
for(int i = 0; i < 10000; i++) {
list.add("I'm a - " + String.valueOf(i));
}
}
public int count(){
return list.size();
}
public String getAt(int i){
return list.get(i);
}
}
The standard deployment procedure contains 3 steps:
- Writing a smart contract
- Correct spelling for verification (Pressing the “Build” button)
- Deployment (Pressing the “Deploy” button)
The picture below represents the Credit Desktop Wallet window which displays methods of our smart contract, after clicking the “Build” button.
Adding elements to an array
Requesting the number of elements
Element by index