Smart Contract for sending Solana Coin(Sol) from one wallet to another wallet - send

I'm going to create a smart contract to send Sol from one wallet to another wallet on Solana.
I'm using Phantom wallet.
How to implement the above?

You can transfer sol directly from the client application(basically ts) or you can create a contract to do so via Cross Program Invocation
Export keypair from your Phantom wallet(and store it in a safe place or use a dummy) and use it to sign the transaction.
For Cross Program Invocation -
use invoke() to call the system program-
// Transfer from PAYER to PAYEE a specific amount:
invoke(
&system_instruction::transfer(payer.key, payee.key, amount),
&[payer.clone(), payee.clone()],
)?;
Check out Solana Bytes and its Github.

Related

How to use selfPermit with Multicall?

Modern AMM routers (eg UniswapV3, Trident) feature an abstract contract selfPermit.sol that allow users to submit their own ERC712 permit signature and call another contract function in a single transaction.
As per Uniswap documentation, "These functions are expected to be embedded in multicalls to allow EOAs to approve a contract and call a function that requires an approval in a single transaction.".
I cannot find any web3 reference implementation of how this work though. How to use Multicall to selfPermit + do action (eg swap) in a single transaction?
note: ERC712 signature process is clear, the question is focused on selfPermit w/ Multicall
Looking for a web3.js illustrative implementation.

Why do I get a warning about the verification code of my RSK Testnet address?

I have connected my web3 instance to the public testnet of RSK and after creating my wallet using rsk.accounts.wallet.create(1, entropy) and receiving some tRBTC from the faucet, I get the following when I go on the RSK Testnet Explorer.
The reason that you see what you see in the screenshot is due to the checksum. RSK uses EIP-1191 for checksums, which means that the combination of lower-cased and upper-cased letters in the address is different from that of what would would get when using a library that uses EIP-55.
So, what can you do about this?
(1) Use a different software library that supports EIP-1191. Be sure to pass in the chainId (30 for RSK Mainnet, 31 for RSK Testnet), otherwise the checksum will be the same as an EIP-55 one.
(2) Use a workaround, to ignore/ bypass checksum verification on your address. You can switch to all lower-case or all upper-case in order to do so. Note that this explicitly skips verification in both EIP-55 and EIP-1191.
Edit to add more detail:
Here's the reference material regarding checksums on RSK: https://developers.rsk.co/rsk/architecture/account-based/#checksum
If the purpose is to check if you can actually use the this address,
the best thing to do would be to check that you can sign messages
with the private key linked to this address.
There are 2 common ways to do this:
(1) On-chain: Sign a transaction. Send a nominal amount of RBTC to another EOA or an SC. This will incur gas fees, of course.
(2) Off-chain: Sign an arbitrary text message.
You can do so programmatically using eth_sign,
for example signer.signMessage in ethers.js
If do not wish to do so programmatically,
and instead use a DApp and browser wallet,
follow these instructions on how to verify address ownership on RSK

How to avoid metamask confirmation in web3js

I am trying to call following function from my solidity contract using web3js frontend.
function playerData(address player) public {
gameStatus[player] = false;
}
webjs calls this method using following line of code.
await myContract.methods.playerData(playerAddress)
.send(
{
from: playerAddress,
}
)
Now when this line is executed, metamask window opens up and waits for confirmation. As there is no token transfer involved in this method, I want to remove confirmation step of metamask.
Please help me understand if there is a way to call this method without confirmation popup from metamask.
Thanks!
If you are going to change the state of the blockchain ( modify a State variable ), you'll need to create a transaction, and since transactions are signed by a user you'll need a wallet ( in this case metamask ) to confirm that transaction.
Metamask is a wallet, a simple app ( be it browser extension or physical USB ) that allows someone to interact with a blockchain account using a private key, in this case you use the wallet to sign the transaction and paying for the gas fees.
If you are NOT changing any State variable, just make your functions view or pure and you won't get the pop-up for metamask.
Now, if you DO change a State variable, the only way you could do it without using metamask is by getting a web3js account object from a private key, and manually signing it with this account ( check out this ), now I heavily advise against this unless you know what you're doing, because if you publish your private key somewhere, anyone will be able to access your account.

How can i get my token funded with LINK from user through solidity?

My contract needs LINK token in order to function.
I want to let users fund LINK tokens to the contract via a function on the contract, and then do some logic for the user based on their funding.
How can i make this possible within the contract?
I've tried to do calls like this.
LINK.balanceOf(walletaddress) does work, (It gets the link amount that's in the wallet).
However, this function below does not work for some reason.
It goes through and all, but with like empty data.
Metamask shows differently when i do the same call from their front-end button. (I assume it does the same as remix does)
https://testnet.bscscan.com/token/0x84b9B910527Ad5C03A9Ca831909E21e236EA7b06#readContract
Here is how i try to get my contracts approval.
function approveTransfer(uint256 amount) public returns(string memory) {
uint256 approveAmt = amount * 10**18;
LINK.approve(_msgSender(),approveAmt);
approvedAmount = approveAmt;
}
Okay, so i kept searching and searching and searching....
Until i found something amazing on their discord channel. (It's most likely written somewhere else too).
Harry | Chainlink
The LINK token is an ERC677 with transferAndCall functionality. So
depending on how your smart contract function call that generates the
random number is made, you can change it to be a 'transferAndCall'
function instead of one that just does the VRF request, with the idea
being that it will transfer enough LINK to fulfill the VRF request.
Then in your consuming contract that does the VRF request, you
implement the 'onTokenTransfer' function which simply calls your other
function that does the VRF request. The end result of this is that
when the user transfers LINK to the contract, it automatically does a
VRF request all in the 1 single transaction.
So instead of the user pressing a button which calls the function in
your consuming contract to do the VRF request, they press a button
which does a 'transferAndCall' function from the LINK token contract,
which in turn transfer LINK to your consuming contract and calls the
'onTokenTransfer' function in your consuming contract, which then
calls your function to do the VRF request, which will be successfully
fulfilled because it just received LINK for the request
See an implementation of this in my previous hackathon entry "Link Gas Station"
https://github.com/pappas999/Link-Gas-Station/blob/master/contracts/WeatherCheck.sol
https://github.com/pappas999/Link-Gas-Station/blob/master/src/relayer/relayer.js
So in short, this is possible because my contract have the
function onTokenTransfer(address from, uint256 amount, bytes memory data) public {
receivedTokenTransfer = true;
lastDepositer = from;
lastDepositerAmountInLink = amount / 10**18;
}
I can therefor instead of sending LINK to my own contract, i can send LINK to LINK's contract address, with the data payload transferAndCall , MycontractAddress, and the amount of LINK my contract should receive.
Upon this payment is sent, chainlink will send my contract the payment and call the function called onTokenTransfer (On my contract). :)))
Ho0pe this helps someone in the future.
Not possible from within your contract, unless the external contract explicitly allows it or contains a security flaw using deprecated tx.origin instead of msg.sender.
See the last paragraph and code snippet in this answer to see how it could be misused if it were possible.
When your contract executes LINK's function, msg.sender in the LINK contract is now your contract - not the user.
Both transfer() and approve() (in order to call transferFrom() later) functions rely on msg.sender, which you need to be the user. But it's not - it's your contract.
When your contract delegates a call to LINK's function, the state changes are stored in your contract - not in the LINK.
But you'd need to store the state changes in the LINK contract, so this is not an option either.

BEP-20 Contract no deploy public view functions

I am studying how to make BEP-20 tokens. For this I copied the following contract in remix to be able to study it:
Contract in BscScan
If I copy the whole file and compile it in Remix, when I deploy it it doesn't show me any getters. No public view function appears. If I look at the contract displayed on the testnet, it doesn't have any supply of tokens either.
I separated the files and libraries for a better reading. And it is then, when I try to display it, that I get the following error:
VM error: revert. revert The transaction has been reverted to the initial state. Note: The called function should be payable if you send value and the value you send should be less than your current balance. Debug the transaction to get more information.
It gives me the feeling that this contract does not generate the tokens ... What am I wrong?
I managed to fix the problem. As I suspected, in order to deploy the contract I have to remove everything related to uniswap and cakeswap. This displays the contract correctly.
If you wanted to deploy the contract with the uniswap interfaces in injected web3, you would need the uniswap testnet.
I found a test address for cake here:
Binance Smart change tesnet