On the time of this announcement, the SDK is formally in beta. It’s obtainable for all, open supply, on GitHub and NPM. Compound.js works within the internet browser and Node.js. It has only one dependency: the newest model of Ethers.js.
Constructed with simplicity in thoughts, builders can write intuitive, one-line strategies to initialize JSON RPC requests that work together with the Compound Protocol.
Along with Compound strategies, builders could make generic Ethereum learn and write calls to any good contract. Lastly, REST API calls will be made to the Compound API that’s hosted by Compound Labs.
Studying and writing from the blockchain will be accomplished swiftly with Compound.js; no have to initialize an object.
Within the following examples, A JSON RPC supplier or Web3 supplier will be handed because the
supplier attribute within the choices object. When writing to the blockchain, a personal key or mnemonic will be handed within the choices object as properly.
Write to the Blockchain (eth_sendTransaction)
Write operations are initialized with Compound.eth.trx. The return worth is an Ethers.js transaction object. Right here is an instance for sending ETH within the internet browser.
Learn from the Blockchain (eth_call)
Studying from any good contract on the blockchain will be accomplished utilizing Compound.eth.learn. Right here is an instance for studying the USDC steadiness within the Uniswap USDC-ETH pair.
A contract ABI may also be handed to the choices object. In that case, you’d then present a string of the strategy identify because the second parameter, as an alternative of the entire technique definition.
Easy one-liners can be found for main protocol strategies like provide, redeem, borrow, repayBorrow, and extra.
In examples like the next, a Compound object have to be instantiated first. The constructor can have
window.ethereum handed within the browser, or a personal key/mnemonic alongside a JSON RPC supplier should you’re utilizing Node.js.
Supplying to the Protocol
Right here is an instance for supplying Ether to the Compound Protocol utilizing Compound.js.
Extra examples of object initialization and deeper description of the transaction choices parameter can be found within the Compound.js GitHub repository readme.
Governance and COMP Strategies
The SDK has elegant strategies for Compound governance performance by means of the COMP and Governor good contracts.
Right here is an instance for fetching the quantity of COMP token that has accrued for an tackle (extra on COMP Distribution right here).
Voting on a Compound governance proposal is as easy utilizing the SDK’s castVote technique.
Extra governance associated strategies are outlined within the Compound.js Documentation.
Fetching costs from the Open Value Feed will be accomplished with the getPrice technique.
The primary parameter is the asset that you really want the worth of, and the second parameter (non-compulsory) is the asset you need that value transformed to. The default output is USD with 6 decimal locations.
This technique helps all property which might be posted to the Open Value Feed, and likewise cTokens.
The Compound REST API will be queried utilizing Compound.js. Every of the obtainable providers has their very own technique.
Compound.js is in open beta and is obtainable at no cost on NPM. The plan for subsequent steps is so as to add extra Compound Protocol associated strategies for ease of growth. Additionally, smarter logging of errors and outcomes would vastly enhance the developer expertise.
Do not forget that the Compound Protocol is decentralized and upgraded by the group. Consequently, this SDK will morph nevertheless the group sees match!
A group contribution information might be obtainable sooner or later for anybody to assist enhance the SDK.
When you have questions or feedback, please be a part of the Compound Discord and ship us a message within the #💻growth channel.