Requesting Binance Smart Chain *Staking Contract Boilerplate* for Visual Code - binance

Hi can anyone recommend one or a reliable updated STAKING Smart Contract boilerplate for binance smart chain? Which i can modify the stack, if im using this to let others stake the custom BSC token I want to provide.
I am working on liquidity for my token. And 2.) Can anyone recommend a FARMING smart contract boiler plate also for my tokens, but for Binance smart chain.
Sincerely.

Related

How to get all balances for some account using Web3.js and Node.js?

I'm new in the blockchain technology, moreover in some dev tasks related to the blockchain. Nevertheless, suddnely I was asked to implement such a demo back-end Node.js app that:
Task: Get information about all tokens for some wallet address.
For example:
Input:
The wallet address is: 0xB245ac044E3c2e9781C9c848249E2e6b186b080F
Output:
ERC-20 tokens: USDT $100, USDC $200, SHIB $300;
Etherum native token: ETH $500.
I'm not asking about ready-to-use code snippet (but why not?), rather it would be better to know which steps should be proceeded in general using Node.js and Web3.js specifics.
Where I've tried to find the answer:
Stackoverflow: How to get all tokens by wallet address
Stackoverflow: web3.js how to search all the contracts ever created by and address
Stackexchange: How to get all contracts deployed by the address, given the address?
Github: ERC-20-Token-Balance (cool and very simple hello-world project)
Medium: Try out Ethereum using only nodejs and npm!
Each of these helps to understand some moments, but the whole solution is still not obvious for me.
It is very possible that I am missing something for input, also possible that my output is incorrect in some moments. But I hope the general idea of the question is clear more or less.
I'll split your question into several steps, as there is no simple way to fetch the data from the blockchain in the format you want, so you have to "walk a thorny path".
1. Get the list of Token Addresses owned by an Externally-Owned-Account
1.1 Query for Transfer events
A token, or better to say - a contract, which implements the ERC20 interface, emits an event Transfer(address from, address to, uint256 amount) Event every time the token transfer occurs. You can query the blockchain for the past events, where the to is your target account. The event emitters are the contracts, possibly the ERC20 tokens, but also those could be the ERC721 tokens, as they have the same event signature in the interface.
Also notice, an event emitter could be any contract, even not related to tokens, as any contract can emit any event.
Some blockchain nodes could limit the block ranges per request to get the events from, so you have to implement the pagination, as you want to get events from block 0 to latest
1.2 Find out the ERC20 Tokens
You have here several options
a. You can create the list of known tokens from various 3rd party sources (CoinmarketCap, 1inch, Shushiswap, Uniswap) and then filter those Transfer emitters narrowed to those from the known list.
b. Another option, is to fetch ERC20 interface Information directly from the blockchain. Call each Transfer emitter by getting the decimals, name, symbol, balanceOf. If you don't get the exception for the calls, then the contract is highly likely the ERC20 token.
c. Or you can get the contracts ABI (if the contract is validated) from Etherscan, and check if everything from ERC20 interface exists in the ABI.
I have implemented all these steps in the 0xweb cli tool, which uses the dequanto library. You can check the implementation in CTokens.ts#L88
After these steps, you'll get the list of all tokens owned by the account, and their amounts (balanceOf).
2. Get the token prices
Another challenging task, in case you don't use any 3rd party service and stick to onchain data.
a. Query the oracle price feeds like chain.link. But not all tokens are presented there.
b. Get the price directly from DEX, like uniswap, sushiswap, pancakeswap etc. But surprise - no easy way to get the price also here. You can find a stable pair (Some USD stable coin/Your Token), if the pair exists just grab the reserves and the ratio is the price. For less popular tokens there could be only the ETH/YourToken pair, and the price for ETH you can get these steps a) or b).
I've written a more in-depth article: https://dev.kit.eco/ethereum-get-token-price-at-a-specific-block-onchain on how to get the price at any time in the past. And if you don't have the archive node, you just get the price for the latest block.
If you want me to explain some parts in detail, don't hesitate to ask in the comments, I'll update the answer then.

Blockchain substrate pallet_membership use cases?

Let me know if I am on the right train of thought. I'm currently building a dapp that will be based on my own parachain, and I was wondering if by adding this pallet, it would be a way to allow users in my dapp to pay for membership.
Obviously I would have to have some extrinsic functions that are exposed through my dapp so that when they click and pay for membership, in the runtime, the membership pallet will add that user as a member. Can anyone confirm my thoughts on this?
This leads up to another question. Should I just create a smart contract to handle membership logic and deploy it on edgeware or some other parachain that already exists?
obviously I would have to have some extrinsic functions that are exposed through my dapp so that when they click and pay for membership, in the runtime, the membership pallet will add that user as a member. Can anyone confirm my thoughts on this?
You can easily do this. pallet_membership is just a container for members. As you will find in the pallet_membership::Config, there are special origins that can be defined as those who have the authority to add or remove a member.
You need a new pallet that will handle the payment to join new members. Let's call this pallet_membership_payment. Once pallet_membership_payment has received the correct payment, it can call into pallet_membership::add_member with whatever origin is required to satisfy it. Not that even if the origin requirement of add_member is EnsureRoot, pallet_membership_payment can still practically get over it, if it is coded as such.
Should I just create a smart contract to handle membership logic and deploy it on edgeware or some other parachain that already exists.
The answer to this really depends on how much further logic does your application have next to handling this membership via fees. Also, it depends on the smart contract payment model (end user pays the fees) works for you If this is it, then it is pretty simple. You might have an easier time in a smart contract model. But, if you need certain optimisations, less fees, more performance etc. you will probably have to consider being your own (para)chain.

TP in lib/script.js vs. assetRegistry from composer-client to update an asset?

I'm looking at knowing, In order to update a asset,
When should I need to write Transaction in lib/script.js
vs.
when should I be using composer-client code using bizNetworkConnection.getAssetRegistry?
I see that I cant use the feature of event emission in later case, Is there any other reason why I should be using it?
Please help me know.
The important thing about writing a Transaction is that it becomes part of the Agreed Smart Contract. So the creation of one or more assets or participants in the same transaction with the associated logic is agreed. This Transaction is a class and can have a specific ACL rule associated with it (also in the smart contract), whereas if you use composer-client you would add individual assets or participants using a generic system transaction AddAsset or AddParticipant.
So writing your code in a Transaction provides a 'better' Blockchain app with a stronger Smart Contract and improved security.

new stripe implementation for Node.js

currently I'm using the node stripe implementation
https://github.com/stripe/stripe-node
this implementation gives me error,
Sending credit card numbers directly to the Stripe API is generally unsafe. We suggest you use test tokens that map to the test card you are using
so I need to user stripe.createToken(); in order to do safe payment or need to configure the stripe account to allow unsafe payments which will be additional task.
how can I implement stripe.createToken(); with Node Js. I couldn't find any hints related to this. additionally only I have found stripe elements and JavaScript codes which can only be implemented from the front-end.
I couldn't
find any hints related to this. additionally only I have found stripe
elements and JavaScript codes which can only be implemented from the
front-end.
In almost all cases it is a bad idea to try to tokenize the card on your server side(i.e from Node). If you have the raw credit card number on your server, you open yourself up to issues with PCI compliance(see the section under Directly to the API) and potential attacks. That's one of the main reasons to use Stripe, it means that you don't need to store and process sensitive credit card data yourself, you just deal with tokens.
It's highly recommended that you always tokenize on the client side, using Checkouts or Elements. That way the frontend speaks directly to Stripe and your code never sees and sensitive credit card information. There are other advantages to using those technologies, such as improved fraud protection and supporting alternative payment methods such as mobile payments(Apple Pay/Google Pay) easily as well.

Signed contracts between two parties in hyperledger composer

Im fairly new to the hyperledger scene and i'm doing a research project regarding DLT apps. In the scenario i'm researching it would be preferred for two parties to be able to sign a contract. I know this is possible in the raw hyperledger SDK in the form of signed chaincode but i would also like to make use of the modelling language end ease of composer.
My question:
is it possible to generate, sign, deploy, instantie and call chaincode from within composer apps? If not what would be an alternative solution for doing so within composer? I'm thinking about defining a contract model but i'm not sure how to make sure both parties sign and attain ownership of said contract 'asset'; considering the nature of assets on the ledger.
Thanks in advance.
If you model a signature transaction, then your transaction processor function can consider your contract asset "signed" when it has 2 signatures, each submitted by different participants to the contract.
E.g. something like (not tested):
asset Contract {
Participant[] parties
Participant[] signatories
}
transaction Signature {
--> Contract contract
}
Pseudo code for TP function:
When a Signature is received, if the currentParticipant() is in the set of parties for the contract, and is not in the signatories, then add them to the signatories.
A contract is signed when all elements in the parties array are also in the signatories array.

Resources