Stake MATIC with Figment Tutorial
Requirements :
- Ledger Enteprise with Smart contract Interaction support (to activate this feature on your workspace, please reach out to your Technical Account Manager)
- LAM setup
- Admin access to the Ledger Enteprise Application
How to start :
- Create your API users
- Create an Ethereum Account (that owns MATIC ERC20 tokens), with a dedicated Smart Contract goverance rule, as MATIC Staking; please note that unlike other currencies, such as Solana, where staking operations are managed by the Staking rule, MATIC staking is managed by the Smart Contract governance rule
- Add the relevant API users to the MATIC Staking Smart Contract governance rule, based on your business workflows.
import requests
import json
Environment variables
LAM_URL = "https://matic-staking.minivault.ledger-sbx.com/lam"
API_USER_NAME = "bluestar" #The username of the API Operator you set as Creator in the Smart Contract rule of your MATIC Staking account
HEADER = {'X-Ledger-API-User': API_USER_NAME}
Create your programmatic staking operation request
Important
Before delegating MATIC, you need to approve Polygon's official StakeManager contract address (0x5e3Ef299fDDf15eAa0432E6e66473ace8c13D908
on Ethereum Mainnet) so that your ERC20 tokens can be delegated. To learn more about approvals, please head here.
Below is an example of a request body to approve Polygon's StakeManager contract for a 0.2 MATIC delegation (on Goerli).
payload = {
"account_name": "MATIC Staking",
"amount": "0",
"coin_fields": {
"contract_interaction": {
"abi": [
{
"constant":false,
"inputs":[
{
"name":"spender",
"type":"address"
},
{
"name":"value",
"type":"uint256"
}
],
"name":"approve",
"outputs":[],
"payable":false,
"stateMutability":"nonpayable",
"type":"function"
}
],
"function_arguments": {
"spender": "0x00200eA4Ee292E253E6Ca07dBA5EdC07c8Aa37A3",
"value": "200000000000000000"
},
"function_name": "approve"
}
},
"max_fees": "1000000000000000000",
"note": {
"content": "Approve StakeManager for MATIC staking",
"title": "MATIC Staking"
},
"recipient": "0x7D1AfA7B718fb893dB30A3aBc0Cfc608AaCfeBB0",
"speed": "FAST"
}
r = request.post(LAM_URL + "/transactions", json=payload, headers=HEADER)
r.json
You can initiate your MATIC staking request programmatically by calling the POST/transactions
endpoint. Below is an example of a request body to create a request to stake 0.2 MATIC with Figment, using function name & arguments (no encoding required).
Important
Please keep in mind that the addresses in these examples are test addresses on Goerli, and do not correspond to Figment's validator address on Ethereum mainnet. Figment's validator address on mainnet is: 0xb929B89153fC2eEd442e81E5A1add4e2fa39028f
.
payload = {
"account_name": "MATIC Staking",
"amount": "0",
"coin_fields": {
"contract_interaction": {
"abi": [
{
"constant":false,
"inputs":[
{
"internalType":"uint256",
"name":"_amount",
"type":"uint256"
},
{
"internalType":"uint256",
"name":"_minSharesToMint",
"type":"uint256"
}
],
"name":"buyVoucher",
"outputs":[],
"payable":false,
"stateMutability":"nonpayable",
"type":"function"
}
],
"function_arguments": {
"_amount": "200000000000000000",
"_minSharesToMint": "2423"
},
"function_name": "buyVoucher"
}
},
"max_fees": "1000000000000000000",
"note": {
"content": "Stake MATIC with Figment",
"title": "MATIC Staking"
},
"recipient": "0xb929B89153fC2eEd442e81E5A1add4e2fa39028f",
"speed": "FAST"
}
r = request.post(LAM_URL + "/transactions", json=payload, headers=HEADER)
r.json
Alternatively, if you already have the encoded contract payload, you can directly input it in your request body.
payload = {
"account_name": "MATIC Staking",
"amount": "0",
"coin_fields": {
"contract_interaction": {
"contract_data": "0x6ab1507100000000000000000000000000000000000000000000000002c68af0bb1400000000000000000000000000000000000000000000000000000000000000000977"
}
},
"max_fees": "1000000000000000000",
"note": {
"content": "Stake MATIC with Figment",
"title": "MATIC Staking"
},
"recipient": "0xb929B89153fC2eEd442e81E5A1add4e2fa39028f",
"speed": "FAST"
}
r = request.post(LAM_URL + "/transactions", json=payload, headers=HEADER)
r.json
Once the transaction is fully approved, it will be signed and broadcast. You will have succesfully staked your MATIC, and will start earning rewards. You can monitor your staking positions by heading to the Official Polygon Staking app, loging in using WalletConnect, and heading to your Account.