#
Quick startLet’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 codebuild
: folder for compiled filesnode_modules
: dependenciestests
: folder with testsasconfig.json
: config file for the asc compiler
Next, update 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.
#
BuildingTo build the contracts use asbuild:
As a result, a file will be created:
#
TestingFor testing, we recommend using jest. Run the command to install it:
Update the "test"
value in your project package.json
file in the scripts
section as follows:
In the tests folder, create the index.test.js
file.
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:
#
DeployingTo deploy your contract you can use rpc.idena.io.
- Connect to the Idena node
- Enter your coinbase address
- Select the compiled
.wasm
contract file - Enter unique
nonce
- Specify
args
for the contract constructor if needed - You can call the
contract_estimateDeploy
method to calcaultemaxfee
parameter
Response example:
As a 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.