Skip to main content

OpenAccount

Opens an account on the ledger.

Initializes the account on-chain, making it ready to receive deposits and execute transactions. Returns the opened account and a transaction reference for monitoring the ledger operation.

Method Options​

Authorisation specification of the OpenAccount method.

TypeMETHOD_TYPE_WRITE
Access LevelMETHOD_ACCESS_LEVEL_AUTHORISED
Roles
  • ROLE_WALLET_ADMIN
  • ROLE_WALLET_ACCOUNT_ADMIN

Parameters​

Request and response parameter message overview:

Input: OpenAccountRequest Message​

FieldTypeRequiredDescription
Name

string

False

The resource name of the account to open. Format: accounts/{ULIDv2}.

Returns: OpenAccountResponse Message​

FieldTypeDescription
LedgerTransaction

string

Transaction reference for monitoring the ledger operation to open the account. The Account is open once this transaction has succeeded. Format: transactions/{ULIDv2}.

Code Examples​

Select supported SDK in the language of your choice for a full example of how to invoke the this method:

package main

import (
"context"
"io"
"log"

transaction_v1 "github.com/meshtrade/api/go/ledger/transaction/v1"
account_v1 "github.com/meshtrade/api/go/wallet/account/v1"
)

func main() {
ctx := context.Background()

// Default configuration is used and credentials come from MESH_API_CREDENTIALS
// environment variable or default discovery methods. Zero config required
// unless you want custom configuration.
accountService, err := account_v1.NewAccountService()
if err != nil {
log.Fatalf("Failed to create service: %v", err)
}
defer accountService.Close()
transactionService, err := transaction_v1.NewTransactionService()
if err != nil {
log.Fatalf("Failed to create transaction service: %v", err)
}
defer accountService.Close()

// Call the OpenAccount method
response, err := accountService.OpenAccount(
ctx,
&account_v1.OpenAccountRequest{
// Resource name of account to open
Name: "accounts/01HQ3K5M8XYZ2NFVJT9BKR7P4C",
},
)
if err != nil {
log.Fatalf("OpenAccount failed: %v", err)
}
log.Printf(
"OpenAccount completed successfully with ledger transaction %s submitted",
response.GetLedgerTransaction(),
)

// get a stream to monitor the state of the account opening transaction
stream, err := transactionService.MonitorTransactionState(
ctx,
&transaction_v1.MonitorTransactionStateRequest{
Name: response.GetLedgerTransaction(),
},
)
if err != nil {
log.Fatalf("MonitorTransactionState failed: %v", err)
}
log.Printf("Stream opened to monitor AddSignatoryToAccount transaction state")

// read from the stream until completion
monitorTransction:
for {
response, err := stream.Recv()
if err == io.EOF {
break // Stream completed normally
}
if err != nil {
// Other errors:
// - timeout of ctx passed to MonitorTransactionState
// - arbitrary network errors
// - other arbitrary errors
log.Fatalf("MonitorTransactionState failed: %v", err)
}

// Process each response as it arrives
log.Printf("Received: %+v", response.GetState())

// Check for transaction end state
switch response.GetState() {
case transaction_v1.TransactionState_TRANSACTION_STATE_SIGNING_IN_PROGRESS,
transaction_v1.TransactionState_TRANSACTION_STATE_SUBMISSION_IN_PROGRESS,
transaction_v1.TransactionState_TRANSACTION_STATE_INDETERMINATE:
log.Printf("OpenAccount transaction in state %s, keep waiting...", response.GetState())

case transaction_v1.TransactionState_TRANSACTION_STATE_SUCCESSFUL:
log.Printf("OpenAccount transaction successful")
break monitorTransction

case transaction_v1.TransactionState_TRANSACTION_STATE_FAILED:
log.Printf("OpenAccount transaction failed")
break monitorTransction

default:
log.Fatalf("Received unexpected transaction state: %v", response.GetState())
}
}
}

Advanced Configuration​

For advanced client configuration options (custom endpoints, TLS settings, timeouts), see the SDK Configuration Guide.

Other Methods​