### Query all proposals - JavaScript Example Source: https://docs.stakestone.io/stakestone/developers/stakestone-api-references JavaScript example using Web3 to call getProposals() on the Proposal contract. Requires the contract address and ABI. ```javascript // Javascript example var Web3 = require('web3'); const BigNumber = require('bignumber.js'); const web3 = new Web3("RPC Endpoint Url"); // Need Proposal contract address const CONTRACT_ADDRESS = ""; const ABI = [{ "inputs": [], "name": "getProposals", "outputs": [ { "internalType": "address[]", "name": "addrs", "type": "address[]" } ], "stateMutability": "view", "type": "function" }]; var contract = new web3.eth.Contract(ABI, CONTRACT_ADDRESS); contract.methods.getProposals().call({ from: "CALLER_ADDRESS" }, function(error, result){ if(!error) { console.log('Response:', result); } else { console.log(error); } }); ``` -------------------------------- ### JavaScript example for roundPricePerShare Source: https://docs.stakestone.io/stakestone/developers/stakestone-api-references Web3.js example to call roundPricePerShare on the StoneVault contract. Requires the contract address and ABI. The ABI shown is for the deposit function, but the example calls roundPricePerShare. The result is logged to the console. ```javascript // Javascript example var Web3 = require('web3'); const BigNumber = require('bignumber.js'); const web3 = new Web3("RPC Endpoint Url"); // Need StoneVault contract address const CONTRACT_ADDRESS = ""; const ABI = [ { "inputs": [], "name": "deposit", "outputs": [ { "internalType": "uint256", "name": "mintAmount", "type": "uint256" } ], "stateMutability": "payable", "type": "function" }]; // Round 1. const ROUND = 1; var contract = new web3.eth.Contract(ABI, CONTRACT_ADDRESS); contract.methods.roundPricePerShare(ROUND).call({ from: "CALLER_ADDRESS" }, function(error, result){ if(!error) { console.log('Response:', result); } else { console.log(error); } }); ``` -------------------------------- ### JavaScript example for getStrategies Source: https://docs.stakestone.io/stakestone/developers/stakestone-api-references JavaScript example using web3.js to call the getStrategies function on the StrategyController contract. Requires the contract address and ABI. ```javascript // Javascript example var Web3 = require('web3'); const BigNumber = require('bignumber.js'); const web3 = new Web3("RPC Endpoint Url"); // Need StrategyController contract address const CONTRACT_ADDRESS = ""; const ABI = [{ "inputs": [], "name": "getStrategies", "outputs": [ { "internalType": "address[]", "name": "addrs", "type": "address[]" }, { "internalType": "uint256[]", "name": "portions", "type": "uint256[]" } ], "stateMutability": "view", "type": "function" }]; var contract = new web3.eth.Contract(ABI, CONTRACT_ADDRESS); contract.methods.getStrategies().send({ from: "CALLER_ADDRESS" }, function(error, result){ if(!error) { console.log('Response:', result); } else { console.log(error); } }); ``` -------------------------------- ### JavaScript example for requestWithdraw Source: https://docs.stakestone.io/stakestone/developers/stakestone-api-references A JavaScript example using web3.js to call requestWithdraw on the StoneVault contract, withdrawing 1 STONE. ```javascript // Javascript example var Web3 = require('web3'); const BigNumber = require('bignumber.js'); const web3 = new Web3("RPC Endpoint Url"); // Need StoneVault contract address const CONTRACT_ADDRESS = ""; const ABI = [{ "inputs": [ { "internalType": "uint256", "name": "_shares", "type": "uint256" } ], "name": "requestWithdraw", "outputs": [], "stateMutability": "nonpayable", "type": "function" }]; // Withdraw 1 STONE. const WITHDRAW_AMOUNT = 1e18; var contract = new web3.eth.Contract(ABI, CONTRACT_ADDRESS); contract.methods.requestWithdraw(WITHDRAW_AMOUNT).send({ from: "CALLER_ADDRESS" }, function(error, result){ if(!error) { console.log('Response:', result); } else { console.log(error); } }); ``` -------------------------------- ### JavaScript example for proposalDetails Source: https://docs.stakestone.io/stakestone/developers/stakestone-api-references JavaScript sample using web3.js to call the proposalDetails method on the Proposal contract. Requires the contract address and ABI. ```javascript // Javascript example var Web3 = require('web3'); const BigNumber = require('bignumber.js'); const web3 = new Web3("RPC Endpoint Url"); // Need Proposal contract address const CONTRACT_ADDRESS = ""; const ABI = [{ "inputs": [ { "internalType": "address", "name": "", "type": "address" } ], "name": "proposalDetails", "outputs": [ { "internalType": "address", "name": "proposer", "type": "address" }, { "internalType": "uint256", "name": "deadline", "type": "uint256" }, { "internalType": "uint256", "name": "support", "type": "uint256" }, { "internalType": "uint256", "name": "oppose", "type": "uint256" }, { "internalType": "uint256", "name": "executedTime", "type": "uint256" }, { "internalType": "bytes", "name": "data", "type": "bytes" } ], "stateMutability": "view", "type": "function" }]; var contract = new web3.eth.Contract(ABI, CONTRACT_ADDRESS); contract.methods.proposalDetails(PROPOSAL_ADDRESS).call({ from: "CALLER_ADDRESS" }, function(error, result){ if(!error) { console.log('Response:', result); } else { console.log(error); } }); ``` -------------------------------- ### Deposit ETH JavaScript example Source: https://docs.stakestone.io/stakestone/developers/stakestone-api-references JavaScript example using Web3 to deposit 1 Ether to the StoneVault contract. Requires the contract address and ABI, and sends a transaction from the caller's address. ```javascript // Javascript example var Web3 = require('web3'); const BigNumber = require('bignumber.js'); const web3 = new Web3("RPC Endpoint Url"); // Need StoneVault contract address const CONTRACT_ADDRESS = ""; const ABI = [ { "inputs": [], "name": "deposit", "outputs": [ { "internalType": "uint256", "name": "mintAmount", "type": "uint256" } ], "stateMutability": "payable", "type": "function" }]; // Deposit 1 Ether. const DEPOSIT_AMOUNT = 1e18; var contract = new web3.eth.Contract(ABI, CONTRACT_ADDRESS); contract.methods.deposit().send({ from: "CALLER_ADDRESS", value: BigNumber(DEPOSIT_AMOUNT).toString(10) }, function(error, result){ if(!error) { console.log('Response:', result); } else { console.log(error); } }); ``` -------------------------------- ### JavaScript example for getStrategyValue Source: https://docs.stakestone.io/stakestone/developers/stakestone-api-references JavaScript example using Web3 and BigNumber to call getStrategyValue on the StrategyController contract. Requires RPC endpoint URL and contract address. ```javascript // Javascript example var Web3 = require('web3'); const BigNumber = require('bignumber.js'); const web3 = new Web3("RPC Endpoint Url"); // Need StrategyController contract address const CONTRACT_ADDRESS = ""; const ABI = [{ "inputs": [ { "internalType": "address", "name": "_strategy", "type": "address" } ], "name": "getStrategyValue", "outputs": [ { "internalType": "uint256", "name": "_value", "type": "uint256" } ], "stateMutability": "nonpayable", "type": "function" }]; var contract = new web3.eth.Contract(ABI, CONTRACT_ADDRESS); contract.methods.getStrategyValue().send({ from: "CALLER_ADDRESS" }, function(error, result){ if(!error) { console.log('Response:', result); } else { console.log(error); } }); ``` -------------------------------- ### JavaScript Example for getAllStrategiesValue Source: https://docs.stakestone.io/stakestone/developers/stakestone-api-references JavaScript code using Web3 to call getAllStrategiesValue on the StrategyController contract. ```javascript // Javascript example var Web3 = require('web3'); const BigNumber = require('bignumber.js'); const web3 = new Web3("RPC Endpoint Url"); // Need StrategyController contract address const CONTRACT_ADDRESS = ""; const ABI = [{ "inputs": [], "name": "getAllStrategiesValue", "outputs": [ { "internalType": "uint256", "name": "_value", "type": "uint256" } ], "stateMutability": "nonpayable", "type": "function" }]; var contract = new web3.eth.Contract(ABI, CONTRACT_ADDRESS); contract.methods.getAllStrategiesValue().send({ from: "CALLER_ADDRESS" }, function(error, result){ if(!error) { console.log('Response:', result); } else { console.log(error); } }); ``` -------------------------------- ### JavaScript Example for latestRoundID Source: https://docs.stakestone.io/stakestone/developers/stakestone-api-references JavaScript sample using web3.js to call latestRoundID on the StoneVault contract. Requires the contract address and ABI, and logs the result or error. ```javascript // Javascript example var Web3 = require('web3'); const BigNumber = require('bignumber.js'); const web3 = new Web3("RPC Endpoint Url"); // Need StoneVault contract address const CONTRACT_ADDRESS = ""; const ABI = [{ "inputs": [], "name": "latestRoundID", "outputs": [ { "internalType": "uint256", "name": "", "type": "uint256" } ], "stateMutability": "view", "type": "function" }]; var contract = new web3.eth.Contract(ABI, CONTRACT_ADDRESS); contract.methods.latestRoundID().call({ from: "CALLER_ADDRESS" }, function(error, result){ if(!error) { console.log('Response:', result); } else { console.log(error); } }); ``` -------------------------------- ### JavaScript example for withdrawFeeRate Source: https://docs.stakestone.io/stakestone/developers/stakestone-api-references JavaScript example using Web3 and BigNumber to call withdrawFeeRate on the StoneVault contract. Requires the StoneVault contract address and an RPC endpoint URL. ```javascript // Javascript example var Web3 = require('web3'); const BigNumber = require('bignumber.js'); const web3 = new Web3("RPC Endpoint Url"); // Need StoneVault contract address const CONTRACT_ADDRESS = ""; const ABI = [{ "inputs": [], "name": "withdrawFeeRate", "outputs": [ { "internalType": "uint256", "name": "", "type": "uint256" } ], "stateMutability": "view", "type": "function" }]; var contract = new web3.eth.Contract(ABI, CONTRACT_ADDRESS); contract.methods.withdrawFeeRate().call({ from: "CALLER_ADDRESS" }, function(error, result){ if(!error) { console.log('Response:', result); } else { console.log(error); } }); ``` -------------------------------- ### JavaScript Example for cancelWithdraw Source: https://docs.stakestone.io/stakestone/developers/stakestone-api-references A JavaScript example using Web3 to call the cancelWithdraw function on the StoneVault contract. It requires the contract address and ABI, and sends a transaction to cancel 1 STONE's withdrawal. ```javascript // Javascript example var Web3 = require('web3'); const BigNumber = require('bignumber.js'); const web3 = new Web3("RPC Endpoint Url"); // Need StoneVault contract address const CONTRACT_ADDRESS = ""; const ABI = [{ "inputs": [ { "internalType": "uint256", "name": "_shares", "type": "uint256" } ], "name": "cancelWithdraw", "outputs": [], "stateMutability": "nonpayable", "type": "function" }]; // Cancel 1 STONE's withdrawal. const STONE_AMOUNT = 1e18; var contract = new web3.eth.Contract(ABI, CONTRACT_ADDRESS); contract.methods.cancelWithdraw(STONE_AMOUNT).send({ from: "CALLER_ADDRESS" }, function(error, result){ if(!error) { console.log('Response:', result); } else { console.log(error); } }); ``` -------------------------------- ### Vote for a proposal - JavaScript Sample Source: https://docs.stakestone.io/stakestone/developers/stakestone-api-references JavaScript example using web3.js to call the voteFor method. It requires the Proposal contract address and ABI, and sends a transaction from the caller address. ```javascript // Javascript example var Web3 = require('web3'); const BigNumber = require('bignumber.js'); const web3 = new Web3("RPC Endpoint Url"); // Need Proposal contract address const CONTRACT_ADDRESS = ""; const ABI = [{ "inputs": [ { "internalType": "address", "name": "_proposal", "type": "address" }, { "internalType": "uint256", "name": "_poll", "type": "uint256" }, { "internalType": "bool", "name": "_flag", "type": "bool" } ], "name": "voteFor", "outputs": [], "stateMutability": "nonpayable", "type": "function" }]; var contract = new web3.eth.Contract(ABI, CONTRACT_ADDRESS); contract.methods.voteFor(PROPOSAL_ADDRESS, STONE_AMOUNT, true).send({ from: "CALLER_ADDRESS" }, function(error, result){ if(!error) { console.log('Response:', result); } else { console.log(error); } }); ``` -------------------------------- ### Query the documentation with the ask interface Source: https://docs.stakestone.io/stakestone/llms.txt Perform an HTTP GET request to the documentation's ask endpoint, providing the 'ask' and 'goal' query parameters. The 'ask' parameter is the immediate question, and 'goal' describes the user's ultimate objective. The response contains a direct answer and relevant excerpts. ```http GET https://docs.stakestone.io/stakestone/index.md?ask=&goal= ``` -------------------------------- ### Query current STONE price - JavaScript sample Source: https://docs.stakestone.io/stakestone/developers/stakestone-api-references JavaScript example using Web3.js to call the currentSharePrice function on the StoneVault contract. Requires the contract address and ABI, and logs the response or error. ```javascript // Javascript example var Web3 = require('web3'); const BigNumber = require('bignumber.js'); const web3 = new Web3("RPC Endpoint Url"); // Need StoneVault contract address const CONTRACT_ADDRESS = ""; const ABI = [{ "inputs": [], "name": "currentSharePrice", "outputs": [ { "internalType": "uint256", "name": "price", "type": "uint256" } ], "stateMutability": "nonpayable", "type": "function" }]; var contract = new web3.eth.Contract(ABI, CONTRACT_ADDRESS); contract.methods.currentSharePrice().call({ from: "CALLER_ADDRESS" }, function(error, result){ if(!error) { console.log('Response:', result); } else { console.log(error); } }); ``` -------------------------------- ### Deposit to vault - RPC response Source: https://docs.stakestone.io/stakestone/developers/stakestone-api-references Example JSON-RPC response for a successful deposit transaction, returning the transaction hash. ```json { "id":64, "jsonrpc": "2.0", "result": "TRANSCACTION HASH with 0x prefix" } ``` -------------------------------- ### POST (RPC Endpoint) - Query vote info on certain proposal Source: https://docs.stakestone.io/stakestone/developers/stakestone-api-references Get the proposal details by sending a JSON-RPC eth_call request to the RPC endpoint. ```APIDOC ## POST (RPC Endpoint) ### Description Get the proposal details. ### Method POST ### Endpoint (RPC Endpoint) ### Parameters #### Request Body - **jsonrpc** (String) - Required - "2.0" - **method** (String) - Required - "eth_call" - **params** (Array) - Required - the call data coerced into string array - **id** (Number) - Required - request sequence id, you could use timestamp as id ### Response #### Success Response (200) - **id** (Number) - request sequence id - **jsonrpc** (String) - "2.0" - **result** (String) - TRANSCACTION HASH with 0x prefix #### Response Example ``` { "id":64, "jsonrpc": "2.0", "result": "TRANSCACTION HASH with 0x prefix" } ``` ``` -------------------------------- ### proposalDetails ABI description Source: https://docs.stakestone.io/stakestone/developers/stakestone-api-references ABI JSON for the proposalDetails function, including inputs, outputs, and stateMutability view. ```json { "inputs": [ { "internalType": "address", "name": "", "type": "address" } ], "name": "proposalDetails", "outputs": [ { "internalType": "address", "name": "proposer", "type": "address" }, { "internalType": "uint256", "name": "deadline", "type": "uint256" }, { "internalType": "uint256", "name": "support", "type": "uint256" }, { "internalType": "uint256", "name": "oppose", "type": "uint256" }, { "internalType": "uint256", "name": "executedTime", "type": "uint256" }, { "internalType": "bytes", "name": "data", "type": "bytes" } ], "stateMutability": "view", "type": "function" } ```