How to send USDC from solana-cli command line - solana

I am trying to send USDC from the solana-cli command line but I can't find any example in the documentation. Everything is references to how to do it in javascript importing these 2 libraries.
import * as web3 from "#solana/web3.js";
import * as splToken from "#solana/spl-token";
The first to transfer SOL coin and the second for the rest of the TOKENS. Can be done? does anyone know the command?

The SPL docs contain CLI examples for every possible action with spl-token. To perform a transfer, you can do:
$ spl-token transfer EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v <AMOUNT> <RECEIVER>
Here, we specify the USDC mint EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v, which means that the CLI will attempt to send from the default user's associated token account for USDC.
You can see all of the examples for tranfers at https://spl.solana.com/token#example-transferring-tokens-to-another-user

Related

What is the alternative of "approve" in evm on Solana?

I have several wallets in evm. I give their X token access to my main wallet by calling Contract(x).approve() function. Thus i can make operations with these wallets. Now i want to do same thing on solana with solana web3 library. However i cannot find any function that gives allowance to my main wallet. The X token on Solana uses solana token program.
Correct, you cannot approve tokens using the normal #solana/web3.js package, so you'll have to use the #solana/spl-token package in one of two ways:
approve does it from the client (https://github.com/solana-labs/solana-program-library/blob/edec44180c3349abd77677acb2270a00121f2936/token/js/client/token.js#L905)
createApproveInstruction creates the instruction which you must include in a Transasction and then send (https://github.com/solana-labs/solana-program-library/blob/edec44180c3349abd77677acb2270a00121f2936/token/js/client/token.js#L1570)

solana transfer nft to any address web3js

I want to make a transfer from my wallet to another wallet with code. I use web3.js and I made a Solana transfer, but I don't know how to make an NFT transfer.
NFTs on Solana are represented as SPL tokens, which can be transferred in JS using the "#solana/spl-token" package on npm: https://www.npmjs.com/package/#solana/spl-token
There's an example of how to use it at https://github.com/solana-labs/solana-program-library/blob/master/token/js/examples/createMintAndTransferTokens.ts and in the repo tests.
You can find more information on SPL tokens at https://spl.solana.com/token
NFT transfer is same as normal spl-token transfer.
Prior to transfer NFT, you need to know its Token Mint Address or its Associated Token Account of yours.
Also need to know receiver's Associated Token Account of NFT Mint Token Account.
If receiver doesn't have associated token account, you or he need to create it first.
If you are not familiar with the account types, please read my article on medium.
https://medium.com/#blockchainlover2019/how-to-verify-ownership-of-metaplex-nft-programmatically-at-on-chain-1059418c3c6
Transferring token by using web3 is easy and not knowhow knowledge.
This is my code from Solana program (smart contract), which transfers nft from one to another.
let transfer_ix = spl_token::instruction::transfer(
token_program.key,
nft_account_to_send.key,
nft_account_to_receive.key,
&pda,
&[],
1
)?;
invoke_signed(
&transfer_ix,
&[
nft_account_to_send.clone(),
nft_account_to_receive.clone(),
pda_account.clone(),
token_program.clone(),
],
&[&[&b"nft_transfer_is_easy"[..], &[_nonce]]]
)?;
I will add another code for you, which runs on web3.

Bash: making a variable available everywhere (not a question on EXPORT)

I have a bit of an odd problem that I need an elegant solution to. I am using a build tool that requires logging in to a service (AWS CodeArtifact specifically). When I login via CLI, it sets an environment variable - let's call this TOKEN. When I run any build, it requires presence of TOKEN to authenticate.
Now, after logging in, builds in the same shell work but obviously, builds in new shells (which aren't sub-shells) fail because TOKEN is of course not defined. I'm looking at ways to solve this; ideally a solution that does something like this:
Login shell: after logging in, save TOKEN in ~/.token
All shells: run something every minute which sets TOKEN to the value in ~/.token
I have 2 questions:
Is this the best way - or is there something more elegant?
If so, what's the best way to do (2) above?
The final catch is that this is something I'll be distributing to end users on their machines, so it would be great if its easily scriptable.
Thanks in advance - stay safe!
When question 2 is answered, the solution for question 1 is simple:
Start writing a function that will return the token.
TOKEN=$(get_token)
The first implementation will recalculate a fresh token without any caching or sharing.
How often do you need the token? When you don't build every minute, an extra job (cronjob) refreshing the token every minute is not needed. In such a case you can refresh the token before each api-call by calling the function. You do not need to store or share it.
When you do need the TOKEN very often, you can modify the function. Using a file is straight forward, but you can also use another solution like a server (when you want the token available on remote hosts for users who have been identified with some other token).
How to automate the manual process for getting a new token, is the next challenge.
Can you find a method, where you do not need to enter a password (something like using .aws/config or (better) assigning the right roles to your server)? Or do you need to script the call with expect?
The API call get-authorization-token requires the codeartifact:GetAuthorizationToken and sts:GetServiceBearerToken permissions.

Create and return Github token from bash

The first time we run hub, it asks for our Github username and password. This is never stored. Instead, hub uses it to create a personal access token that gets saved in your account and then it uses that token for subsequent uses.
Is there a way to achieve the same from a bash script, without registering an application and all that?
This script will be public.
without registering an application
Not exactly, since it is part of the oauth workflow.
But from a simple shell, you can store your GitHub username and password in a credential helper like libsecret (Mac) or manager (Windows).
In that case, you won't have to enter said credentials again and you don't have to register anything directly on GitHub.

Sharing a Google Drive file without sending notification email

I am using Google Drive Java API. I need to copy a file from one Google domain to another, so my approach is the following:
authenticate with source domain service account
share file with user in destination domain
authenticate with destination domain service account and impersonate
the user
copy the original file from origin domain to destination domain
delete the share permission from the original file
Everything works as expected except that I don't want the destination owner to receive the Google Drive email notifying him about the shared file. When the file is shared via the Web GUI one can disable the notification email so I guess this is also possible via the API, the question is how ^^ Anyone?
PS: I am open to new 'less tedious' methods to create a copy of a file from one domain to another if that is possible.
On step 2, when sharing the file with the new user, you'll be using the permissions.insert() API call. You'll want to specify the sendNotificationEmails=false parameter along with this call to suppress the email notification.
In the Google Drive API V3 with permissions.create() it has changed to singular: sendNotificationEmail=false
In a POST request it would be like this:
https://www.googleapis.com/drive/v3/files/*FILEID*/permissions?sendNotificationEmail=false

Resources