Access services Smart Contract, which allows creating the connection between IoT devices and the Near Protocol Blockchain.
- Create a registry for a device group
- Add device to registry
- Set/Get device data
- Set/Get device metadata
- Set/Get device data parameters
- Set/Get device metadata parameters
- Install rustup
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -
Restart the terminal
-
Add wasm target to your tool chain:
rustup target add wasm32-unknown-unknownVisit https://www.rust-lang.org/tools/install for more info.
-
Install node.js version>=12 (https://nodejs.org/es/download/package-manager/)
-
Install Near-CLI
sudo npm i -g near-cli-
Create a Near testnet account in (https://wallet.testnet.near.org/)
-
Account access
near login- Install git
sudo apt install git- Clone the project
git clone https://github.com/paul-cruz/ConnectIoT.git- Go to the project directory
cd Connect-IoT- Install libsqlite3-dev
sudo apt install libsqlite3-dev- Install build-essential
sudo apt install build-essential- Compile release version
cargo build --target wasm32-unknown-unknown --releaseYou can check the contract ID in the .env file. To deploy this smart contract, run:
near dev-deploy ./target/wasm32-unknown-unknown/release/connect_iot.wasmBefore using the smart contract, for a better and easy usage, you can set environment variables for CONTRACT_ACCOUNT_ID and OWNER_ACCOUNT_ID.
export CONTRACT_ACCOUNT_ID=<ID in .env file>Your OWNER_ACCOUNT_ID is your testnet account
export OWNER_ACCOUNT_ID=<example.testnet> near call $CONTRACT_ACCOUNT_ID create_registry '{"registry_name":"REGISTRY_NAME"}' --accountId $OWNER_ACCOUNT_IDnear call $CONTRACT_ACCOUNT_ID add_device_to_registry '{"registry_name":"REGISTRY_NAME","device_name":"DEVICE_NAME","description":"DESCRIPTION"}' --accountId $OWNER_ACCOUNT_IDIt is important to know that data is an Unordered Map, so you can input as many key/value items in it.
near call $CONTRACT_ACCOUNT_ID set_device_data '{"registry_name":"REGISTRY_NAME","device_name":"DEVICE_NAME","data":"{\"\":\"\"}"}' --accountId $OWNER_ACCOUNT_IDnear call $CONTRACT_ACCOUNT_ID get_device_data '{"registry_name":"REGISTRY_NAME","device_name":"DEVICE_NAME"}' --accountId $OWNER_ACCOUNT_IDIt is important to know that parameter and value are Strings, so you can only input a parameter & value per function call.
near call $CONTRACT_ACCOUNT_ID set_device_data_param '{"registry_name":"REGISTRY_NAME","device_name":"DEVICE_NAME","param":"DATA_PARAMETER","value":"VALUE"}' --accountId $OWNER_ACCOUNT_IDnear call $CONTRACT_ACCOUNT_ID get_device_data_param '{"registry_name":"REGISTRY_NAME","device_name":"DEVICE_NAME","param":"DATA_PARAMETER"}' --accountId $OWNER_ACCOUNT_IDIt is important to know that metadata is an Unordered Map, so you can input as many key/value items.
near call $CONTRACT_ACCOUNT_ID set_device_metadata '{"registry_name":"REGISTRY_NAME","device_name":"DEVICE_NAME","metadata":{"{}":"{}"}}' --accountId $OWNER_ACCOUNT_IDnear call $CONTRACT_ACCOUNT_ID get_device_metadata '{"registry_name":"REGISTRY_NAME","device_name":"DEVICE_NAME"}' --accountId $OWNER_ACCOUNT_IDIt is important to know that parameter and value are Strings, so you can only input a parameter & value per function call.
near call $CONTRACT_ACCOUNT_ID set_device_metadata_param '{"registry_name":"REGISTRY_NAME","device_name":"DEVICE_NAME","param":"METADATA_PARAMETER","value":"VALUE"}' --accountId $OWNER_ACCOUNT_IDnear call $CONTRACT_ACCOUNT_ID get_device_data_param '{"registry_name":"REGISTRY_NAME","device_name":"DEVICE_NAME","param":"METADATA_PARAMETER"}' --accountId $OWNER_ACCOUNT_IDTo run tests, run the following command
cargo test Or go to the test code in lib.rs and press Run test if using Visual Studio Code.
near call $CONTRACT_ACCOUNT_ID create_registry '{"registry name":"my_registry"}' --accountId $OWNER_ACCOUNT_IDYou can check this transaction and its details at the Near Testnet Explorer. https://explorer.testnet.near.org/transactions/3tLWruvx3YGHBKuNVZBXspk1PBoryizMuQamqC3Ubq4s
near call $CONTRACT_ACCOUNT_ID add_device_to_registry '{"registry_name":"my_registry","device_name":"my_device","description":"Temperature"}' --accountId $OWNER_ACCOUNT_IDYou can check this transaction and its details at the Near Testnet Explorer. https://explorer.testnet.near.org/transactions/24hztKUH7YW6Xpw8HiT55uqSyqfSzYaszS41A4WzWwso
near call $CONTRACT_ACCOUNT_ID set_device_data '{"registry_name":"my_registry","device_name":"my_device","data":"{\"sample1\": \"value1\", \"sample2\": \"value2\", \"sample3\": \"value3\"}"}' --accountId $OWNER_ACCOUNT_IDYou can check this transaction and its details at the Near Testnet Explorer. https://explorer.testnet.near.org/transactions/EjjP8UNGdQZYv6kKnS8MQ5QNNXPnEWsXdH2BVg5cdSze
near call $CONTRACT_ACCOUNT_ID set_device_metadata '{"registry_name":"my_registry","device_name":"my_device","metadata":"{\"battery\": \"87%\", \"date\": \"11/12/2019\", \"location\": \"orchard\"}"}' --accountId $OWNER_ACCOUNT_IDYou can check this transaction and its details at the Near Testnet Explorer. https://explorer.testnet.near.org/transactions/AVrMu5s4JtwbT8c2tj8FXCYmyFqsBCi4VhCWebYRACS6
near call $CONTRACT_ACCOUNT_ID get_device_data '{"registry_name":"my_registry","device_name":"my_device"}' --accountId $OWNER_ACCOUNT_IDYou can check this transaction and its details at the Near Testnet Explorer. https://explorer.testnet.near.org/transactions/DJMaTHFopcrGkWQW765Y8eceTbwPo6K58MFKBNyLhhfQ
Reach out via website or send an email to info@mexbalia.com
.png)







