FeeShare registration
The x/FeeShare module allows smart contracts to receive a portion of the gas fees generated by interactions with the contract. Use this guide to learn how to register your contract and earn a portion of transaction fees. For more information on this module, visit the FeeShare spec.
Register an existing contract
Using Terrad
You can use Terrad to register your contract with the following commands. Be sure to use the appropriate flags when submitting the transaction.
The following command can only be used by the contract's admin. If the contract has no admin, only the creator can use it.
To use the command, specify the following:
[contract]
: The address of the deployed contract.[withdraw]
: An address to which the portion of the fee revenue will be sent.[your_address]
: The address of the signer.
Using a JSON message
The following example is a JSON message that can be sent to register a contract address in the FeeShare module.
_6 {_6 "@type": "/juno.feeshare.v1.MsgRegisterFeeShare",_6 "contract_address": "terra1w8ta7vhpzwe0y99tvvtp7k0k8uex2jq8jts8k2hsyg009ya06qts5fwftt",_6 "deployer_address": "terra1880xn49l4x947pjv4a9k2qe5mf423kjzkn4ceu",_6 "withdrawer_address": "terra1zdpgj8am5nqqvht927k3etljyl6a52kwqup0je"_6 },
Using feather.js
- In this example, the first portion of the code is used to import the feather.js SDK, set up the accounts, and prepare the environment by initializing Terra's Light Client Daemon and setting up the wallets and accounts.
-
Next, a contract is registered with the FeeShare module by executing a
MsgRegisterFeeShare
transaction. This message is created by supplying it with the following addresses:contractAddress
: The address of the deployed contract.deployerAddress
: The address of the deployer of the contract.withdrawerAddress
: An address to which the portion of the fee revenue will be sent.
- In this example, the first portion of the code is used to import the feather.js SDK, set up the accounts, and prepare the environment by initializing Terra's Light Client Daemon and setting up the wallets and accounts.
-
Next, a contract is registered with the FeeShare module by executing a
MsgRegisterFeeShare
transaction. This message is created by supplying it with the following addresses:contractAddress
: The address of the deployed contract.deployerAddress
: The address of the deployer of the contract.withdrawerAddress
: An address to which the portion of the fee revenue will be sent.
Register a new contract
Use the following example to instantiate your contract and register with the FeeShare module.
Setup
- The first portion of the code is used to import the necessary functions, classes, and objects from the feather.js SDK.
- The next few lines prepare the environment by initializing Terra's Light Client Daemon and setting up the wallets and accounts.
Deploy the contract
- This code creates and signs a transaction to store the smart contract on the blockchain. It waits for the transaction to be completed and gets the contract's code id from the result.
- A contract instantiation message is created and signed to deploy the contract to the blockchain. The contract has an initial balance of
1uluna
. It waits for the transaction to be completed and gets the contract address from the result.
Register with the FeeShare module
The contract is registered with the FeeShare module by executing a MsgRegisterFeeShare
transaction. This message is created by supplying it with the following addresses:
contractAddress
: The address of the deployed contract.deployerAddress
: The address of the deployer of the contract.withdrawerAddress
: An address to which the portion of the fee revenue will be sent.
Check for fees
- In this example, a transaction is created by executing the sample contract's
change_owner
message along with a fee of400000uluna
for the transaction.
- To check that the FeeShare is working properly, the
withdrawer_address
is queried. In this code, the expected portion of fees sent to a contract's registeredwithdrawer_address
is0.500000000000000000
, or half of the fees. If the module is working properly, half of the fees (200000uluna
) are expected to be sent to thewithdrawer_address
.
Setup
- The first portion of the code is used to import the necessary functions, classes, and objects from the feather.js SDK.
- The next few lines prepare the environment by initializing Terra's Light Client Daemon and setting up the wallets and accounts.
Deploy the contract
- This code creates and signs a transaction to store the smart contract on the blockchain. It waits for the transaction to be completed and gets the contract's code id from the result.
- A contract instantiation message is created and signed to deploy the contract to the blockchain. The contract has an initial balance of
1uluna
. It waits for the transaction to be completed and gets the contract address from the result.
Register with the FeeShare module
The contract is registered with the FeeShare module by executing a MsgRegisterFeeShare
transaction. This message is created by supplying it with the following addresses:
contractAddress
: The address of the deployed contract.deployerAddress
: The address of the deployer of the contract.withdrawerAddress
: An address to which the portion of the fee revenue will be sent.
Check for fees
- In this example, a transaction is created by executing the sample contract's
change_owner
message along with a fee of400000uluna
for the transaction.
- To check that the FeeShare is working properly, the
withdrawer_address
is queried. In this code, the expected portion of fees sent to a contract's registeredwithdrawer_address
is0.500000000000000000
, or half of the fees. If the module is working properly, half of the fees (200000uluna
) are expected to be sent to thewithdrawer_address
.