Smart Contract | Access Control

The access control of your contract is an important concept that governs many features provided by your smart contract.

Swagger Docarrow-up-right | ReDocarrow-up-right

Almost every smart contract must have an access control mechanism. We provide two:

  1. Ownership

  2. Role-Based Access Control

Ownership

"Ownership" is a simple approach to set up access control within your smart contract. You can easily provide the "accessControl" property with "OWNABLE" during deploymentarrow-up-right to get started. Thereby, the restricted areas of the contract can only be called by the owner of the contract.

Get smart contract owner.

curl -X GET "http://0.0.0.0:7000/nftkit/nft/accessControl/chain/MUMBAI/contract/0xf277BE034881eE38A9b270E5b6C5c6f333Af2517/owner"

  • Path parameter:

chain: chain to work with.

Main chains: ETHEREUM, POLYGON

Testnet chains: RINKEBY, ROPSTEN, MUMBAI, SHIMMEREVM

contract: smart contract address

Transfer ownership of the contract to a new account.

curl -X POST "http://0.0.0.0:7000/nftkit/nft/accessControl/chain/MUMBAI/contract/0xf277BE034881eE38A9b270E5b6C5c6f333Af2517/ownershipTransfer" \
-H  "Content-Type: application/json" \
-d '{"account":"0x8448Ff4b2733b52f62d81ca46d64bD16786299Cd"}'

  • Path parameter:

chain: chain to work with.

Main chains: ETHEREUM, POLYGON

Testnet chains: RINKEBY, ROPSTEN, MUMBAI, SHIMMEREVM

contract: smart contract address

Renounce ownership of the smart contract.

  • Path parameter:

chain: chain to work with.

Main chains: ETHEREUM, POLYGON

Testnet chains: RINKEBY, ROPSTEN, MUMBAI, SHIMMEREVM

contract: smart contract address

Role-Based Access Control

"Role-Based Access Control" is a more complex approach than "Ownership" to manage access control. With this approach, you can define a hierarchy of roles, each allowed to perform a different set of actions. You can also assign multiple accounts to each role.

Verify if an account has been granted role

  • Path parameter:

chain: chain to work with.

Main chains: ETHEREUM, POLYGON

Testnet chains: RINKEBY, ROPSTEN, MUMBAI, SHIMMEREVM

contract: smart contract address

account: an account address

role: role name

As we have a role hierarchy, You can use this API to get role admin that controls a sub role.

  • Path parameter:

chain: chain to work with.

Main chains: ETHEREUM, POLYGON

Testnet chains: RINKEBY, ROPSTEN, MUMBAI, SHIMMEREVM

contract: smart contract address

role: role name

Grant role to account. The caller must have role's admin role.

  • Path parameter:

chain: chain to work with.

Main chains: ETHEREUM, POLYGON

Testnet chains: RINKEBY, ROPSTEN, MUMBAI, SHIMMEREVM

contract: smart contract address

Revoke role to account. The caller must have role's admin role.

  • Path parameter:

chain: chain to work with.

Main chains: ETHEREUM, POLYGON

Testnet chains: SEPOLIA, GOERLI, MUMBAI, SHIMMEREVM

contract: smart contract address

Renounce role from the calling account.

  • Path parameter:

chain: chain to work with.

Main chains: ETHEREUM, POLYGON

Testnet chains: SEPOLIA, GOERLI, MUMBAI, SHIMMEREVM

contract: smart contract address

Last updated

Was this helpful?