Skip to content

Instantly share code, notes, and snippets.

@lucas-maicoin
Last active June 28, 2018 04:53
Show Gist options
  • Save lucas-maicoin/07ca1ec1101b8a891f24c0a21c67c9f4 to your computer and use it in GitHub Desktop.
Save lucas-maicoin/07ca1ec1101b8a891f24c0a21c67c9f4 to your computer and use it in GitHub Desktop.
EOS Permissions

Update key in a permission

$ cleos set account permission lucaszhang11 active '{"threshold": 1, "keys": [{"key": "EOS64fsvNKzjEoKCDH7u2zhKAouNWt2xAqWN5dxpLfMnVd17uGNYp", "weight": 1}], "accounts": []}' owner
executed transaction: 34063ebd1312c6704aa3978e0327ea996df43148cc44da49c223b48d7f587e70  160 bytes  649 us
#         eosio <= eosio::updateauth            {"account":"lucaszhang11","permission":"active","parent":"owner","auth":{"threshold":1,"keys":[{"key...
warning: transaction executed locally, but may not be confirmed by the network yet

$ cleos get account lucaszhang11
permissions:
     owner     1:    1 EOS5ZxpFzmqybRZjoBt9Xavb3PrYBG8LNf91aag2KaCdE1nEb2G8Y
        active     1:    1 EOS64fsvNKzjEoKCDH7u2zhKAouNWt2xAqWN5dxpLfMnVd17uGNYp
memory:
     quota:     7.954 KiB    used:     2.926 KiB

net bandwidth:
     delegated:       0.1000 EOS           (total staked delegated to account from others)
     used:               161 bytes
     available:        47.34 KiB
     limit:             47.5 KiB

cpu bandwidth:
     delegated:       0.1000 EOS           (total staked delegated to account from others)
     used:               719 us
     available:        8.595 ms
     limit:            9.314 ms

multiple keys in a permission

$ cleos set account permission lucaszhang11 active '{"threshold": 2, "keys": [{"key": "EOS64fsvNKzjEoKCDH7u2zhKAouNWt2xAqWN5dxpLfMnVd17uGNYp", "weight": 1}, {"key": "EOS7nSQEwdC5rTBu9CPAoQib8gpb9SyWoTrZ5ZXdqk5Ae8FrDd5vW", "weight": 1}], "accounts":[]}' owner
executed transaction: 42d926eba55b280bbc182d6f443977ed1a4c9f8f4ea7f153f6abbf9df1a3a2de  200 bytes  664 us
#         eosio <= eosio::updateauth            {"account":"lucaszhang11","permission":"active","parent":"owner","auth":{"threshold":2,"keys":[{"key...
warning: transaction executed locally, but may not be confirmed by the network yet

permissions:
     owner     1:    1 EOS5ZxpFzmqybRZjoBt9Xavb3PrYBG8LNf91aag2KaCdE1nEb2G8Y
        active     2:    1 EOS64fsvNKzjEoKCDH7u2zhKAouNWt2xAqWN5dxpLfMnVd17uGNYp, 1 EOS7nSQEwdC5rTBu9CPAoQib8gpb9SyWoTrZ5ZXdqk5Ae8FrDd5vW
memory:
     quota:     7.954 KiB    used:     2.975 KiB

net bandwidth:
     delegated:       0.1000 EOS           (total staked delegated to account from others)
     used:               359 bytes
     available:        47.15 KiB
     limit:             47.5 KiB

cpu bandwidth:
     delegated:       0.1000 EOS           (total staked delegated to account from others)
     used:             1.493 ms
     available:        7.821 ms
     limit:            9.314 ms

add custom permission

$ cleos set account permission lucaszhang11 p.transfer '{"threshold":2,"keys":[{"key":"EOS64fsvNKzjEoKCDH7u2zhKAouNWt2xAqWN5dxpLfMnVd17uGNYp","weight":1},{"key":"EOS7nSQEwdC5rTBu9CPAoQib8gpb9SyWoTrZ5ZXdqk5Ae8FrDd5vW","weight":1}],"accounts":[]}' active
executed transaction: add7fd673f67f104dfe0c0707c5fe84754bee90d2ed3a7fb03cc724ad44c43d1  208 bytes  793 us
#         eosio <= eosio::updateauth            {"account":"lucaszhang11","permission":"p.transfer","parent":"active","auth":{"threshold":2,"keys":[...
warning: transaction executed locally, but may not be confirmed by the network yet

$ cleos get account lucaszhang11
permissions:
     owner     1:    1 EOS5ZxpFzmqybRZjoBt9Xavb3PrYBG8LNf91aag2KaCdE1nEb2G8Y
        active     2:    1 EOS64fsvNKzjEoKCDH7u2zhKAouNWt2xAqWN5dxpLfMnVd17uGNYp, 1 EOS7nSQEwdC5rTBu9CPAoQib8gpb9SyWoTrZ5ZXdqk5Ae8FrDd5vW
           p.transfer     2:    1 EOS64fsvNKzjEoKCDH7u2zhKAouNWt2xAqWN5dxpLfMnVd17uGNYp, 1 EOS7nSQEwdC5rTBu9CPAoQib8gpb9SyWoTrZ5ZXdqk5Ae8FrDd5vW
memory:
     quota:     7.954 KiB    used:     3.354 KiB

net bandwidth:
     delegated:       0.1000 EOS           (total staked delegated to account from others)
     used:               562 bytes
     available:        46.96 KiB
     limit:             47.5 KiB

cpu bandwidth:
     delegated:       0.1000 EOS           (total staked delegated to account from others)
     used:             2.264 ms
     available:        7.051 ms
     limit:            9.315 ms

remove permission

$ cleos set account permission lucaszhang11 p.transfer 'NULL' active

add multiple accounts in a permission

cleos set account permission lucaszhang11 active '{"threshold":2,"keys":[{"key":"EOS64fsvNKzjEoKCDH7u2zhKAouNWt2xAqWN5dxpLfMnVd17uGNYp","weight":1},{"key":"EOS7nSQEwdC5rTBu9CPAoQib8gpb9SyWoTrZ5ZXdqk5Ae8FrDd5vW","weight":1}],"accounts":[{"permission":{"actor":"testaccount11","permission":"active"},"weight":1},{"permission":{"actor":"testaccount12","permission":"active"},"weight":1}]}' owner

add permission on an action

$ cleos set action permission lucaszhang11 eosio.token transfer p.transfer
executed transaction: 80a50584a1be61db8e495901cf0c9c2cbb65aeb4f70bb937fbc4a4536c2b6fcc  144 bytes  728 us
#         eosio <= eosio::linkauth              {"account":"lucaszhang11","code":"eosio.token","type":"transfer","requirement":"p.transfer"}
warning: transaction executed locally, but may not be confirmed by the network yet

1 key can't transfer

$ cleos wallet unlock -n max
$ cleos wallet keys
[
  "EOS64fsvNKzjEoKCDH7u2zhKAouNWt2xAqWN5dxpLfMnVd17uGNYp"
]
$ cleos transfer lucaszhang11 lucaszhang15 "0.0100 EOS" "try p.permission" -p lucaszhang11@p.transfer
Error 3090003: provided keys, permissions, and delays do not satisfy declared authorizations
Ensure that you have the related private keys inside your wallet and your wallet is unlocked.

2 keys can transfer

$ cleos wallet unlock
$ cleos wallet keys
[
  "EOS5ZxpFzmqybRZjoBt9Xavb3PrYBG8LNf91aag2KaCdE1nEb2G8Y",
  "EOS64fsvNKzjEoKCDH7u2zhKAouNWt2xAqWN5dxpLfMnVd17uGNYp",
  "EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV",
  "EOS7nSQEwdC5rTBu9CPAoQib8gpb9SyWoTrZ5ZXdqk5Ae8FrDd5vW"
]
$ cleos transfer lucaszhang11 lucaszhang15 "0.0100 EOS" "try p.permission" -p lucaszhang11@p.transfer
executed transaction: 023bbf42bbccb762f9d235a6a7934ec30bf499f50e7f8a47f42732f2d54be4e6  160 bytes  775 us
#   eosio.token <= eosio.token::transfer        {"from":"lucaszhang11","to":"lucaszhang15","quantity":"0.0100 EOS","memo":"try p.permission"}
#  lucaszhang11 <= eosio.token::transfer        {"from":"lucaszhang11","to":"lucaszhang15","quantity":"0.0100 EOS","memo":"try p.permission"}
#  lucaszhang15 <= eosio.token::transfer        {"from":"lucaszhang11","to":"lucaszhang15","quantity":"0.0100 EOS","memo":"try p.permission"}
warning: transaction executed locally, but may not be confirmed by the network yet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment