Module allow ct.js connect NEAR Blockchain to sign transactions and interact with your smart-contract.
- Import catmod into ct.js and enable it to start usage.
- Open catmod settings and fill all you contract details: Network, Contract Address and method names.
We support 2 smart-contracts: primary (required) and secondary (optional). To start using each smart-contract - provide contract address, view and call method manes as js array of strings).
ct.near.isConnected
ct.near.userAddress
Primary contract address:
ct.near.primaryAddress
Secondary contract address:
ct.near.secondaryAddress
Primary contract:
ct.near.primaryContract
Secondary contract:
ct.near.secondaryContract
Add connect action to your Connect button template (On Step):
ct.near.connect();
Add disconnect action to your button template (On Step):
ct.near.disconnect();
ct.near.primaryContract.call_method_name(params);
- Create new room with connect button and set it as starting room.
- Add next code to your connect button (On Step):
if (ct.pointer.collides(this, undefined, true)) {
ct.near.connect();
}
NOTE: In this example we use Pointer catmod, but you can replace to Touch or Mouse usage.
- Put next code into "On Step" room events to redirect user when account will be connected:
if(ct.near.isConnected) {
ct.rooms.switch('MainMenu');
}
You can render connected user wallet address and represent in short form (for long addresses):
this.userAccount = ct.near.userAddress;
if (ct.near.userAddress.length > 14) {
this.userAccount = ct.near.userAddress.slice(0, 8) + '...' + ct.near.userAddress.slice(-4);
}
this.accountLabel = new PIXI.Text(this.userAccount);
this.addChild(this.accountLabel);
this.accountLabel.x = 30;
this.accountLabel.y = 30;
this.accountLabel.depth = 1000;
const data = await ct.near.primaryContract.read_data_method();
NOTE: read_data_method should exist in your smart-contract and listed in catmod settings.
await ct.near.primaryContract.add_user_scores({
param_id: "test data"
});
NOTE: call_data_method should exist in your smart-contract and listed in catmod settings.