1Money Network
  • Getting Started
  • Overview
  • Developer Guide
  • Quick Start
  • User Guides
    • Custodians & Centralized Exchanges (CEXs)
    • Issuers
  • Validators
  • Integrations
    • Overview
    • Network Access
    • SDKs
      • Typescript
        • Get Started
        • API Methods
      • Golang
        • Get Started
        • API methods
      • Rust
    • REST APIs
      • Chains
        • Get Chain Id
      • Accounts
        • Get account by token
        • Get account nonce
      • Tokens
        • Issue token
        • Get token metadata
        • Update token metadata
        • Grant authority
        • Mint
        • Burn
        • Managelist
        • Pause/Unpause
      • Checkpoints
        • Get the latest Checkpoint number
        • Get checkpoint by number
        • Get checkpoint by hash
      • Transactions
        • Get transaction by hash
        • Get transaction receipt by hash
        • Submit payment
        • Submit cancellation
        • Estimate fee
    • Websocket
      • Subscribing & Unsubscribing
      • Retrieving Transaction Details
      • Keeping the connection alive
      • Stream | Checkpoints
    • Data Dictionary
      • Transaction Types
        • TokenCreate
        • TokenTransfer
        • TokenGrantAuthority
        • TokenRevokeAuthority
        • TokenBlacklistAccount
        • TokenWhitelistAccount
        • TokenMint
        • TokenBurn
        • TokenCloseAccount
        • TokenPause
        • TokenUnpause
        • TokenUpdateMetadata
          • TokenMetadata Structure
            • MetaDataKeyValuePair
        • Other Transaction Types (WiP)
  • Core Concepts
    • The 1Money Protocol
    • System Components
    • Account Model
    • Token Authority
    • Transactions and Instructions
    • Implementation and usability considerations
    • Security
Powered by GitBook
On this page
  1. Integrations
  2. REST APIs
  3. Transactions

Submit payment

PreviousGet transaction receipt by hashNextSubmit cancellation

Last updated 2 months ago

The following code segment demonstrates a Golang implementation for transaction submission.

import (
	"fmt"
	"github.com/ethereum/go-ethereum/common"
	"github.com/ethereum/go-ethereum/crypto"
	"github.com/ethereum/go-ethereum/rlp"
	"math/big"
)

var privateKey = "01833a126ec45d0191519748146b9e35647aab7fed28de1c8e17824970f964a3"

type PaymentMessage struct {
	ChainID *big.Int
	Nonce   uint64
	To      common.Address
	Value   *big.Int
	Token   *common.Address `rlp:"optional"`
}

type Signature struct {
	R string
	S string
	V uint64
}

func SignMessage(msg *PaymentMessage) (*Signature, error) {
	encoded, err := rlp.EncodeToBytes(msg)
	if err != nil {
		return nil, err
	}
	hash := crypto.Keccak256(encoded)
	fmt.Printf("Signature Hash: %s\n", common.BytesToHash(hash))
	key, err := crypto.HexToECDSA(privateKey)
	if err != nil {
		return nil, err
	}
	sign, err := crypto.Sign(hash, key)
	if err != nil {
		return nil, err
	}
	fmt.Printf("Signature: 0x%x\n", sign)
	fmt.Printf("Raw bytes: %v\n", sign)
	r := sign[:32]
	s := sign[32:64]
	v := sign[64]
	return &Signature{
		R: common.BytesToHash(r).Hex(),
		S: common.BytesToHash(s).Hex(),
		V: uint64(v),
	}, nil
}

func main() {
	tokenAddr := common.HexToAddress("0x2045a425D0e131E747f8be2F044413733e412d7d")
	payment := &PaymentMessage{
		ChainID: big.NewInt(1212101),
		Nonce:   0,
		To:      common.HexToAddress("0x937b9aff6404141681cbf39301aeb869500bbdf0"),
		Value:   big.NewInt(1),
		Token:   &tokenAddr,
	}
	signature, err := SignMessage(payment)
	if err != nil {
		panic(fmt.Sprintf("sign payment msg error: %v", err))
	}
	fmt.Printf("Payment msg Signature: %v\n", signature)
}

post
Body
all ofOptional

Represents token transfer transaction requests to/from REST.

Responses
200Success
application/json
400
Client error
application/json
500
Internal server error
application/json
post
POST /v1/transactions/payment HTTP/1.1
Host: api.testnet.1money.network
Content-Type: application/json
Accept: */*
Content-Length: 345

{
  "chain_id": 1,
  "nonce": 1,
  "recipient": "0x9E1E9688A44D058fF181Ed64ddFAFbBE5CC742Ab",
  "token": "0x9E1E9688A44D058fF181Ed64ddFAFbBE5CC742Ab",
  "value": "1500000000",
  "signature": {
    "r": "72956732934625920503481762689501378577921804342307439094906376029324416116949",
    "s": "29902520081700531224291681396692026253288382272435451874524203378285409371412",
    "v": "1"
  }
}
{
  "hash": "0xf55f9525be94633b56f954d3252d52b8ef42f5fd5f9491b243708471c15cc40c"
}