We’ve built a JavaScript SDK for Ethereum and the Compound Protocol. Compound.js is now in open beta!
Developers can use simple, one-line methods for complex interactions with the Compound Protocol in Node.js and the web browser. In addition to JSON RPC, the SDK implements Compound REST API calls. Lastly, users can do generic reading and writing to and from the Ethereum blockchain (using eth_call
and eth_sendTransaction
under the hood).
Check out the announcement on the Compound blog for more code snippets to get started developing with the SDK.
GitHub: https://github.com/compound-finance/compound-js
NPM: https://www.npmjs.com/package/@compound-finance/compound-js
Here is an example for sending ETH with the SDK.
import Compound from '@compound-finance/compound-js';
const toAddress = '0xa0df350d2637096571F7A701CBc1C5fdE30dF76A';
(async function() {
const trx = await Compound.eth.trx(
toAddress,
'function send() external payable',
[],
{
value: Compound._ethers.utils.parseEther('43.0'),
provider: window.ethereum,
}
);
const toAddressEthBalance = await Compound.eth.getBalance(toAddress);
})().catch(console.error);