Skip to main content

Sending transactions

In the EVM blockchains, there are two distinct types of functions: "View Functions" and "Transaction Functions." In this section, we'll focus exclusively on transaction functions. Unlike view functions, these operations are designed to modify the blockchain's state and execute actions that can involve transferring assets, updating records, or triggering smart contract events.

The main characteristics of the transaction functions are:

  • State Modification: One of the primary characteristics of transaction functions is their capability to modify the blockchain's state. Unlike view functions that are read-only, transaction functions are designed to alter the distributed ledger. This can involve transferring tokens, updating records, changing ownership, or executing any action that causes a change in the blockchain's data.

  • Gas Consumption: Transaction functions come at a cost, often in the form of gas fees. In blockchain ecosystems, "gasLimit" refers to the computational resources required to process and validate transactions. When users initiate transaction functions, they must pay gas fees to incentivize miners or validators to include their transactions in the blockchain. The amount of gas consumed depends on the complexity of the operation and the network's congestion.

  • Transaction validation: Transaction functions undergo a special validation process when users initiate them, which is not present in view functions. This validation ensures that the transaction follows the rules and policies of the blockchain network. Validators or miners check to make sure the transaction is genuine and that its data is accurate, all while adhering to the blockchain's consensus rules. This validation process is specific to transaction functions and sets them apart from view functions, which do not trigger such validation because they are read-only operations.

Executing transaction functions with the Vottun APIs​

Using the Vottun APIs, developers can execute transaction functions of any smart contract in order to retrieve their data. This can be achieved with the /mutable endpoint from our Web3 Core API. For a detailed example of how to perform this operation with the Vottun APIs, head to Send transaction

How to leverage the power of transaction functions​

Now that we have talked about WHY you should use these functions and HOW to perform them, let's see some real examples of the use of transaction functions:

1. Crowdfunding platform: Create shares​

Token creation often involves transaction functions. Suppose you are building a decentralized crowdfunding platform, and you want to mint new tokens to represent shares in a project. You would call a transaction function, such as mintTokens(address investor, uint256 amount), to generate new tokens for investors who contribute. An example of this operation would look like this:

curl --location 'https://api.vottun.tech/core/v1/evm/transact/mutable' \
--header 'Authorization: Bearer <YOUR_API_KEY>' \
--header 'x-application-vkn: <YOUR_APPLICATION_ID>' \
--header 'Content-Type: application/json' \
--data-raw '{
"contractAddress": "0xa0b86991c621..BA20e5A3Aa0C",
"blockchainNetwork": 97,
"method": "mintTokens",
"params": [
"0xC02A3F525f2..597B2ffcaE633a",
15
]
}'

2. DAO: Cast a vote​

Blockchain-based voting systems rely on transaction functions to record votes. In a decentralized governance dApp, users can participate in decision-making by casting their votes. You might call a transaction function like vote(string proposalId, bool inFavor), where users specify the proposal they support and whether they are in favor. An example of this operation would look like this:

curl --location 'https://api.vottun.tech/core/v1/evm/transact/mutable' \
--header 'Authorization: Bearer <YOUR_API_KEY>' \
--header 'x-application-vkn: <YOUR_APPLICATION_ID>' \
--header 'Content-Type: application/json' \
--data-raw '{
"contractAddress": "0xa0b86991c621..BA20e5A3Aa0C",
"blockchainNetwork": 97,
"method": "mintTokens",
"params": [
"3286d277-1632-4644-9401-afe2b7379b91",
true
]
}'

3. Gaming: Transfer in-game assets​

Transaction functions play a crucial role in web3 gaming, allowing players to transfer in-game assets seamlessly. In web3 games, assets like characters, weapons, or collectibles are often represented as non-fungible tokens (NFTs). Imagine you're developing a web3 multiplayer role-playing game, where players can own and trade unique in-game weapons as NFTs. To perform asset transfers, you would call a function like transferWeapon(address recipient, string weaponId). An example of this operation would look like this:

curl --location 'https://api.vottun.tech/core/v1/evm/transact/mutable' \
--header 'Authorization: Bearer <YOUR_API_KEY>' \
--header 'x-application-vkn: <YOUR_APPLICATION_ID>' \
--header 'Content-Type: application/json' \
--data-raw '{
"contractAddress": "0xa0b86991c621..BA20e5A3Aa0C",
"blockchainNetwork": 97,
"method": "transferWeapon",
"params": [
"0xC02A3F525f2..597B2ffcaE633a",
"3286d277-1632-4644-9401-afe2b7379b91",
]
}'