Let’s make a simple custom contract. First, create npm project and install the dependencies:
After project initialization, you will have the following project folder structure:
assembly: folder with contract source code
build: folder for compiled files
tests: folder with tests
asconfig.json: config file for the asc compiler
asconfig.json file so that the asc compiler uses the transformation of the contract code with
idena-sdk-bindgen. For this you need to add the line:
You are ready to write the contract code using
idena-sdk-as. Exported class in the
assembly/index.ts is the entry point for executing the contract.
As an example, see the code of hello-world contract.
To build the contracts use asbuild:
As a result, a file will be created:
For testing, we recommend using jest. Run the command to install it:
"test" value in your project
package.json file in the
scripts section as follows:
In the tests folder, create the
See example of tests for hello-world contract.
To execute the contract code and run the test, you need to install and run Idena node emulator idena-contract-runner. You can build it yourself or download the executable file.
idena-sdk-as contains additional classes and methods for testing, see idena-sdk-tests.
To run tests, use the command:
To deploy your contract you can use rpc.idena.io.
- Connect to the Idena node
- Enter your coinbase address
- Select the compiled
- Enter unique
argsfor the contract constructor if needed
- You can call the
contract_estimateDeploymethod to calcaulte
result you will get a hash of
DeployContractTx transaction. To get the address of the deployed contract, call
bcn_txReceipt method for this transaction hash.