Vote by smart contract
Cast your vote directly on chain by calling smart contracts public function
All published polls would have a clarity smart contract to capture the votes and more details on the chain.
Public function parameters
All deployed smart contracts will have a "cast-my-vote" public function, which accepts the following parameters.
Vote
It is a required field. The data type is a "list of string ASCII" with a limit of 36 characters.
(vote (list 2 (string-ascii 36)))
All selected option ids should be passed here. Option ids are available in poll JSON. The Poll JSON link is attached under the information section on the published Poll screen.
Volume
It is a required field. The data type is a "list of unsigned integers".
(volume (list 2 uint))
A number of votes for each selected option. It should be in the same order as the above option ids.
BNS
It is an optional field. The data type is a "list of string ASCII" with a limit of 256 characters".
(bns (string-ascii 256))
BNS name of the voter. It is required to be passed when the poll strategy is BTC Name holders. Else you can pass an empty string ASCII.
Domain
It is an optional field. The data type is a "Buffer" with a limit of 20 characters".
(domain (buff 20))
The domain of the BTC name. It is required to be passed when the poll strategy is BTC Name holders. Else you can pass an empty buffer.
Namespace
It is an optional field. The data type is a "Buffer" with a limit of 48 characters".
(domain (buff 48))
The namespace of the BTC name. It is required to be passed when the poll strategy is BTC Name holders. Else you can pass an empty buffer.
Token-ids
It is an optional field. The data type is a "list of unsigned integers".
(token-ids (list 60000 uint))
All NFT token holding ids need to be passed here. It is required to be passed when the strategy token type is a Non-fungible token. Else you can pass an empty list.
Definition of the public function
;; Cast your vote
(define-public
(cast-my-vote
(vote (list 2 (string-ascii 36)))
(volume (list 2 uint))
(bns (string-ascii 256))
(domain (buff 20))
(namespace (buff 48))
(token-ids (list 60000 uint))
)
;; Body of the function
)
Call smart contract function to vote
You can use the @stacks/transaction npm package to call clarity smart contract functions. The below-attached link has more information about the smart contract function call.
Last updated