1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
| package main
import ( "bufio" "context" "encoding/base64" "encoding/json" "fmt" "io/ioutil" "log" "os" "strings"
"github.com/algorand/go-algorand-sdk/client/v2/algod" "github.com/algorand/go-algorand-sdk/client/v2/common" "github.com/algorand/go-algorand-sdk/crypto" "github.com/algorand/go-algorand-sdk/mnemonic" "github.com/algorand/go-algorand-sdk/transaction" )
type Config struct { APIEndpoint string `json:"APIEndpoint"` APIToken string `json:"APIToken"` OwnerAddr string `json:"OwnerAddr"` }
func main() { ctx := context.Background() cfg := Config{} content, err := ioutil.ReadFile("./config.json") if err != nil { log.Fatalln("Failed to read config file") } err = json.Unmarshal(content, &cfg) if err != nil { log.Fatalln("Unable to parse config file") }
client, err := common.MakeClientWithHeaders( cfg.APIEndpoint, "X-API-Key", cfg.APIToken, nil, ) if err != nil { log.Fatalln("Failed to make algod client:", err) }
algodClient := algod.Client(*client)
fmt.Println("Input your mnemonic words:") reader := bufio.NewReader(os.Stdin) mn, err := reader.ReadString('\n') if err != nil { log.Fatalln("Failed to read mnemonic words") } mn = strings.TrimSuffix(mn, "\n")
privKey, err := mnemonic.ToPrivateKey(mn) if err != nil { log.Fatalln("Error to get private key from mnemonic key") }
txParams, err := algodClient.SuggestedParams().Do(ctx) if err != nil { log.Fatalln("Error getting suggested tx params:", err) }
txParams.FlatFee = true txParams.Fee = 1000
coinTotalIssuance := uint64(10000000) coinDecimalsForDisplay := uint32(0) accountsAreDefaultFrozen := false managerAddress := cfg.OwnerAddr assetReserveAddress := "" addressWithFreezingPrivileges := cfg.OwnerAddr addressWithClawbackPrivileges := cfg.OwnerAddr assetUnitName := "COINUNIT" assetName := "COINNAME" assetUrl := "https://coinurl.com" assetMetadataHash := "" tx, err := transaction.MakeAssetCreateTxn( cfg.OwnerAddr, uint64(txParams.Fee), uint64(txParams.FirstRoundValid), uint64(txParams.LastRoundValid), nil, txParams.GenesisID, base64.StdEncoding.EncodeToString(txParams.GenesisHash), coinTotalIssuance, coinDecimalsForDisplay, accountsAreDefaultFrozen, managerAddress, assetReserveAddress, addressWithFreezingPrivileges, addressWithClawbackPrivileges, assetUnitName, assetName, assetUrl, assetMetadataHash, )
if err != nil { log.Fatalln("Error creating transaction:", err) }
_, bytes, err := crypto.SignTransaction(privKey, tx) if err != nil { log.Fatalln("Failed to sign transaction:", err) }
txID, err := algodClient.SendRawTransaction(bytes).Do(ctx) if err != nil { log.Fatalln("failed to send transaction:", err) }
log.Println("Transaction successful with ID: ", txID) }
|