I am trying to send coins on the cosmos-sdk blockchain. I succeeded in transferring coins using cosmjs. The code is as follows:
import { Secp256k1HdWallet } from "@cosmjs/amino";
import { StargateClient, SigningStargateClient } from "@cosmjs/stargate";
(async () => {
const toAddress = "your recipient address here";
const rpcEndpoint = "your rpc endpoint here";
const mnemonic = "your mnemonic here";
const wallet = await Secp256k1HdWallet.fromMnemonic(mnemonic, { prefix: "cosmos" });
console.log(wallet);
const [{ address, pubkey }] = await wallet.getAccounts();
console.log(address);
const client = await StargateClient.connect(rpcEndpoint);
console.log("chain id: ", await client.getChainId());
const balance = await client.getAllBalances(address);
console.log("balance: ", balance);
const signingClient = await SigningStargateClient.connectWithSigner(rpcEndpoint, wallet);
console.log("sender balance before: ", await client.getAllBalances(address));
console.log("receipient balance before: ", await client.getAllBalances(toAddress));
const result = await signingClient.sendTokens(address, toAddress, [{ denom: "denom", amount: "800" }], {
amount: [{ denom: "denom", amount: "20" }],
gas: "200000",
});
console.log("result: ", result);
console.log("sender balance after: ", await client.getAllBalances(address));
console.log("receipient balance after: ", await client.getAllBalances(toAddress));
})();
I want to write a new program using golang that performs the same logic as this code. What should I do? I found something similar content, but it's result is not fitted on me.
I want three things. First, I want the same result as when I use "gaiad keys export --unarmored-hex --unsafe" using gaiad. Second, I want to implement the same logic as with cosmjs in golang. Finally, I want a golang example that uses a locally stored key in the most efficient way possible.