GithubHelp home page GithubHelp logo

aptos-go-sdk's Introduction

Aptos Go SDK

License

Install

go get -v github.com/portto/aptos-go-sdk

aptos-go-sdk's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aptos-go-sdk's Issues

INVALID_AUTH_KEY

Error Message : [Validation Code: INVALID_AUTH_KEY](panic: vm_error: Invalid transaction: Type: Validation Code: INVALID_AUTH_KEY)

When I run the token or transactions examples, here is the error info above.

Mainnet call error

example code

package main

import (
	"context"
	"fmt"
	"github.com/portto/aptos-go-sdk/client"
)

func main() {
	//client := client.NewAptosClient("https://aptos-mainnet.nodereal.io/v1/88215d0e3a944e46b367a9f8e5c0a965/v1")
	//client := client.NewAptosClient("https://fullnode.devnet.aptoslabs.com")
	client := client.NewAptosClient("https://aptos-mainnet.pontem.network/v1/")
	info, err := client.LedgerInformation(context.TODO())
	fmt.Println(info, err) //<nil> web_framework_error: not found
}

edge case of getting address string from account address model

There is a bug when getting the address from the account address model.
Assume the address is 0x0111111111111111111111111111111111111111111111111111111111111111
The returned string would be 0x111111111111111111111111111111111111111111111111111111111111111
It is less than 1 character than the normal address because those 0 bytes after 0x prefix are trimmed.

Tranfert transaction issue

Hi guys,
First of all, thanks for developing an aptos sdk in golang. It really helps people like me :)

I ran into a problem while trying to do a simple transfer.
Here is my code...

func transfert(from utils.Account, to utils.Account, aptosValue uint64) error {
	accountInfo, err := aptosClient.GetAccount(ctx, from.Address)
	if err != nil {
		return err
	}
	addr, _ := models.HexToAccountAddress(to.Address)

	tx := models.Transaction{}
	err = tx.SetChainID(settings.ChainID).
		SetSender(from.Address).
		SetPayload(getTransferPayload(addr, aptosValue*settings.AptosUnit)).
		SetExpirationTimestampSecs(uint64(time.Now().Add(10 * time.Minute).Unix())).
		SetGasUnitPrice(settings.GasPrice).
		SetMaxGasAmount(uint64(settings.MaxGasPrice)).
		SetSequenceNumber(accountInfo.SequenceNumber).Error()
	if err != nil {
		return err
	}

	msgBytes, err := tx.GetSigningMessage()
	if err != nil {
		panic(err)
	}

	var pk1, _ = hex.DecodeString(from.PrivateKeyHex[2:])
	priv1 := ed25519.NewKeyFromSeed(pk1)
	signature := ed25519.Sign(priv1, msgBytes)
	var authErr = tx.SetAuthenticator(models.TransactionAuthenticatorEd25519{
		PublicKey: priv1.Public().(ed25519.PublicKey),
		Signature: signature,
	}).Error()
	if authErr != nil {
		panic(authErr)
	}
	rawTx, err := aptosClient.SubmitTransaction(ctx, tx.UserTransaction)
	if err != nil {
		panic(err)
	}

	utils.Log(utils.Info, 0, "Transfert 1 APTOS from "+from.Address+" to "+to.Address+" TX: "+rawTx.Hash)
	return nil
}

func getTransferPayload(to models.AccountAddress, amount uint64) models.TransactionPayload {
	return models.EntryFunctionPayload{
		Module: models.Module{
			Address: addr0x1,
			Name:    "coin",
		},
		Function:      "transfer",
		TypeArguments: []models.TypeTag{aptosCoinTypeTag},
		Arguments:     []interface{}{to, amount},
	}
}

As you can see, it is strongly inspired by your example script. The problem is that this part of the code triggers an error :

	msgBytes, err := tx.GetSigningMessage()
	if err != nil {
		panic(err)
	}

Output : panic: non-optional enum value is nil

I don't see what my script is missing to make it work. I hope you can help me understand the problem if there is one. Thanks in advance.

How to get a custom resource object?

example lp resource

{
  "type": "0x190d44266241744264b964a37b8f09863167a12d3e70cda39376cfb4e3561e12::liquidity_pool::LiquidityPool<0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::WETH, 0x1::aptos_coin::AptosCoin, 0x190d44266241744264b964a37b8f09863167a12d3e70cda39376cfb4e3561e12::curves::Uncorrelated>",
  "data": {
    "coin_x_reserve": {
      "value": "120720489"
    },
    "coin_y_reserve": {
      "value": "2543058577240"
    },
    "dao_fee": "33",
    "fee": "30",
    "last_block_timestamp": "1667533407",
    "last_price_x_cumulative": "437929619665727922872547093989",
    "last_price_y_cumulative": "1702452483005368160082",
    "locked": false,
    "lp_burn_cap": {
      "dummy_field": false
    },
    "lp_mint_cap": {
      "dummy_field": false
    },
    "x_scale": "0",
    "y_scale": "0"
  }
}

I change this mnemonic words generate invalid addresses

I use this bip39 standard to generate mnemonic words "heavy confirm beef vague prevent language panda scrub certain electric fix left" change to your mnemonic but those are invalid.

APTOS,0,0x3bf2cfce46007ba84e4dbf7001719d5e55de28d53b000190aced426306eedb3e
APTOS,1,0x53f4c1177f8d13598de83cdf32d6c8715fbdc55eb58b0406bf268280d3c23f5e
APTOS,2,0x1ae491c1f64102783eec3375b7b3c378cc1b7703bc92a9be131da5743316150f
APTOS,3,0x3d2b430ced4b56ba810098bcc31e6c1be2dbd5abd75790b17cae88e766c4dbf5
APTOS,4,0x4d844c90ab79a393ca5337ea589674f04bbd9cd90bfdafbb4eb44f6ada06db14

help me fixed it please, thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.