Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
@anchor-protocol/anchor-earn
Advanced tools
Changelog
Readme
Anchor Earn is a client SDK for building applications that can interact with the earn functionality of Anchor Protocol from within JavaScript runtimes.
NOTE This SDK only supports the earn functionalities of anchor protocol and cannot be used for other functionalities like bond or borrow.
A walk through of the steps to get started with the Anchor Earn SDK alongside with a few use case examples are provided below.
Anchor Earn is available as a package on NPM and it is independent from other Terra and Anchor SDKs.
To add to your JavaScript project's package.json
as a dependency using preferred package manager:
npm install -S @anchor-protocol/anchor-earn
or
yarn add @anchor-protocol/anchor-earn
Anchor earn uses only Terra.js as a dependency. To get set up with the required dependencies, run:
# debug
yarn install
Anchor earn provides extensive tests for data classes and functions. To run them, after the steps in Dependencies:
# debug
yarn test
Account
objectAnchor Earn provides a facility to create a wallet on the Terra blockchain.
This functionality is accessible through the Account
object.
const account = new Account();
NOTE It is crucial to store or write down your account information before doing any interactions with the SDK. A user can have access to this info by printing the account.
console.log(account.toData());
Account{
acc_address: 'terra1awnxng53rlnzw3lcwwzsydrx2nj2fuas5nm3gm',
public_key: 'terrapub1addwnpepqwke39mta5903ac05a42ug37hs5khrmsw7ffc7lzemy3vwzypjpzqju9f5d',
private_key: <Buffer da 8e 5d b9 c4 df 74 57 9c ea d5 a7 c5 8b 50 80 7e 1c 1c e6 39 ce e2 60 10 9c cd bf 26 36 31 26>,
mnemonic: 'cry pilot west bench pepper jeans joke slow gadget cloud chuckle wedding canal crop dolphin route ridge mouse canoe rural actor luxury guide buzz'
}
private_key
and mnemonic
are essential for later usage.
Wallet
and MnemonicKey
objectsThe Wallet
and MnemonicKey
objects are borrowed from Terra.js, but users have access to them in Anchor Earn without any dependency on Terra.js.
In case users have a previous account on the Terra chain, they can use their private key and MnemonicKey to recover their keys.
import { Wallet, MnemonicKey } from '@anchor-protocol/anchor-earn';
const account = new MnemonicKey({
mnemonic:
'...',
});
Another usage of the wallet
object is being used inside the customSigner. An example is provided in the customSigner section.
AnchorEarn
objectAnchor Earn provides facilities for two main use cases:
AnchorEarn
object.
To create the AnchorEarn
object.const anchorEarn = new AnchorEarn({
chain: CHAINS.TERRA,
network: NETWORKS.BOMBAY_12,
privateKey: account.privateKey,
});
The above example uses the Account
object for instantiating anchor-earn
.
For the case that a user has a previous account on the Terra chain, the user can recover their key using MnemonicKey
and use the following code to instantiate AnchorEarn
.
import { MnemonicKey } from '@anchor-protocol/anchor-earn';
const account = new MnemonicKey({
mnemonic:
'...',
});
const anchorEarn = new AnchorEarn({
chain: CHAINS.TERRA,
network: NETWORKS.BOMBAY_12,
privateKey: account.privateKey,
});
For Terra testnet (bombay-12), users can top up their balance with UST using faucet.
AnchorEarn
helps execute three functionalities:
UST
and AUST
to other accounts
The following code snippets show how to use the AnchorEarn
object.NOTE: Currently, Anchor Earn supports the deposit of the
UST
currency only.
To deposit funds in the Anchor Protocol, use the following example:
const deposit = await anchorEarn.deposit({
amount: '...', // amount in natural decimal e.g. 100.5. The amount will be handled in macro.
currency: DENOMS.UST,
});
To withdraw funds from the protocol, use the following example:
const deposit = await anchorEarn.withdraw({
amount: '...', // amount in natural decimal e.g. 100.5. The amount will be handled in macro.
currency: DENOMS.UST,
});
To send UST
and AUST
to other accounts, use the following example:
(For this functionality, the AUST
denom is also supported.)
const sendUst = await anchorEarn.send({
currency: DENOMS.UST,
recipient: 'terra1....',
amount: '...', // amount in natural decimal e.g. 100.5. The amount will be handled in macro.
});
AnchorEarn
querier facilitates both querying smart contracts and the chain. There are two queries provided by the AnchorEarn
object:
To get the current state of an account, use the following example:
Note: The address of the account must be specified in construction.
const anchorEarn = new AnchorEarn({
chain: CHAINS.TERRA,
network: NETWORKS.BOMBAY_12,
});
const userBalance = await anchorEarn.balance({
currencies: [DENOMS.UST],
});
To get the current state of the market, use the example below:
const market = await anchorEarn.market({
currencies: [DENOMS.UST],
});
Anchor Earn also provides users with the functionality to sign transactions and leave the signed transaction to the SDK to perform the broadcasting.
CustomSigner
is a callback function with which the users can sign deposit
, withdraw
, and send
transactions.
The following code snippet specifies an example of the CustomSigner
usage:
const customSigner = async (tx: Msg[]) => {
const account = new MnemonicKey({
mnemonic:
'...',
});
const wallet = new Wallet(
new LCDClient({
URL: 'https://bombay-lcd.terra.dev',
chainID: 'bombay-12',
}),
account,
);
return await wallet.createAndSignTx({
msgs: tx,
gasAdjustment: 2,
gasPrices: { uusd: 0.15 },
});
};
await anchorEarn.deposit({
amount: '0.01',
currency: DENOMS.UST,
log: (data) => {
console.log(data);
},
customSigner: customSigner,
});
Anchor Earn facilitates a custom broadcast. This can be helpful in the case of applications that rely on external toolings to broadcast transactions. Here is an example of its usage:
const anchorEarn = new AnchorEarn({
chain: CHAINS.TERRA,
network: NETWORKS.BOMBAY_12,
mnemonic:
'...',
});
const customBroadcaster = async (tx: Msg[]) => {
const lcd = new LCDClient({
URL: 'https://bombay-lcd.terra.dev',
chainID: 'bombay-12',
});
const wallet = new Wallet(
lcd,
new MnemonicKey({
mnemonic:
'...',
}),
);
const signedTx = await wallet.createAndSignTx({
msgs: tx,
gasAdjustment: 2,
gasPrices: { uusd: 0.15 },
});
return lcd.tx.broadcastSync(signedTx).then((result) => {
return result.txhash;
});
};
await anchorEarn.withdraw({
amount: '0.01',
currency: DENOMS.AUST,
log: (data) => {
console.log(data);
},
customBroadcaster: customBroadcaster
});
For seeing the progress of the transaction on the chain, loggable
is provided. The following code shows how to use it:
const deposit = await anchorEarn.deposit({
amount: '...',
currency: DENOMS.UST,
log: (data) => {
console.log(data);
}
});
This software is licensed under the Apache 2.0 license. Read more about it here. © 2021 Anchor Protocol
FAQs
Unknown package
The npm package @anchor-protocol/anchor-earn receives a total of 45 weekly downloads. As such, @anchor-protocol/anchor-earn popularity was classified as not popular.
We found that @anchor-protocol/anchor-earn demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.