I'm working on BSCSCAN API. My goal is to get full balance for a given address as you can see on this page:
https://bscscan.com/tokenholdings?a=0x1c82bdb6a93f50a564155ddbcb9cf1b1a244d169
I checked the documentation on BscScan Website, and it seems I just could get:
-BNB BALANCE (not the full token balance) for a given address
-BALANCE of an address by giving the contract address of a single token
While I want to get the full balance for a given address. What is the right endpoints I should use? Thank you in advice.
This API returns the Value of BNB and not the Value of Tokens in BNB
https://api.bscscan.com/api?module=account&action=balance&address=0x0Bb3A1517624Ff45186Df879E9292f67750F8EB0&apikey=YOURAPIKEYBSCSCAN
This API returns the token Balance of and address
https://api.bscscan.com/api?module=account&action=tokenbalance&contractaddress=YOURCONTRACTADDRESS&address=YOURADDRESS&tag=latest&apikey=YOURAPIKEY
Related
Hello I am writing a erc721a solidity smart contract of a nft collection.
And I want to do whitelisted sale and public sale at the same time. So I wonder how can I reserve token IDs #1 to #100 for whitelisted sale and token ID #101 to last token ID for public sale..
Please can someone help me in this case. Thanks :D
I have the following scenario:
I have a contract to generate a limited amount of erc20 tokens. User A buys X amount of this token. Then user A wants to sell some of his tokens, for X amount of ether, then user B wants to buy tokens of user A, how can I automatically transfer tokens from user A to user B when the transfer of ether from user B to user A has been successful be transfer?
Do I need a second contract to handle this kind of operation?
You may have two options,
Play around with Escrow SmartContracts (Like Openzeppelin) and modify it as per your need.
Use ERC20 Approve(spender,amount) on User B, to get allowance for your contract to spend on behalf of B. (spender : Your contract address)
Run a web3 script to listen on events to catch the corresponding transaction of sending ether from B->A ,
once the ether is transferred, you can place a function call to smart contract to spend the token from B to A
In your ERC20 Contract implementation, you can have a mapping of address -> eth, where the eth represents the selling price each user has set up.
Now, when a user "sells" their token, they can allow the same contract to transfer X amount of tokens from their balance which they want to sell.
And to sell, you can create a payable function that receives ether, and via parameter a seller address. This function will dynamically ( using the address received on the mapping we created at the beginning ) transfer X tokens to the buyer, using that seller's token price and the amount of ether received.
For example: If 1TKs = 0.5ETH, and the buyer sends 2eth, the contract will transfer 4TKS.
Recomendation.
Usually, the token contract and the seller/buyer functions are done in different contracts for security reasons, for example having the actual token, and the token shop separated on different contracts.
Disclaimer.
This is the simplest implementation I could think of, but it will accomplish your requirements.
I'm new to solidity and I wanted to develop a subscription contract where a user can subscribe to a merchants plan and pay. But I'm unable to subscribe function and transfer the token to merchant.
I'm using open zeppelin ERC20 standard token to transfer.
IERC20 token = IERC20(plans[planId].token);
token.transferFrom(
payable(msg.sender),
payable(plan.merchant),
plan.amount
);
I don't know why but this keeps giving me allowance error even though I have increased the allowance of the user.
Since you're invoking the token.transferFrom() from the subscription contract, the token owner needs to increaseAllowance() for the subscription contract to manipulate their tokens.
Example:
Your subscription contract is deployed on address 0x123.
Token address is 0x456, and it has 18 decimals.
The user needs to execute increaseAllowance(0x123, 500 * 1e18) on the token contract in order to increase the allowance by 500 tokens.
Mind the subscription contract address as the first param, and the decimals as the second param (so the actual value passed to the second param is 500000000000000000000 because it includes the decimals as units as well).
I am looking at this staking contract (pancake swap):
0x73feaa1ee314f8c655e354234017be2193c9e24e
and it's token (cake):
0x0e09fabb73bd3ade0a17ecc321fd13a19e81ce82
you can find a summary here:
https://bscscan.com/token/0x0e09fabb73bd3ade0a17ecc321fd13a19e81ce82?a=0x73feaa1ee314f8c655e354234017be2193c9e24e
On bscscan, I can get the following information:
price of token $12.54
market cap $2.9b
supply 231m
holders 137k
balance 88m (cake)
With nethereum, when I call:
web3.Eth.GetBalance.SendRequestAsync
I get:
with staking contract address: 479430015101300880
with token address: 3459819507903896496
and I'm not sure what the units are, nor how to map this to the information from bscscan.
I'm trying to get both the token value, but also what is the balance in the contract and I can't seem to find a way to do this.
so I looked at the nethereum playground and found an example dealing with ERC20 tokens, but when I put my addresses in it, the output is 0 and absolutely no error message, etc.
Is it possible to get the Payer ID?
The return_url provides Payer ID, amount etc .. while the cancel_url gives only token.
There was no payment, so no payer, so no payer ID. There was no transaction, so no transaction ID. No money was paid, so no amount.
If you are using the Paypal-PHP-SDK is not possible at this moment, the unique solution for now is save the token when you create the payment. In DEV-MASTER branch they have added a new method called "getToken()" to Payment class, so you will get the token easily when you create a payment. You can track the issue using the next URL Paypal-PHP-SDK issue 832
$payment->create($apiContext);
$token = $payment->getToken();
PS: Remember, this method "getToken()" is only available in DEV-MASTER for now.