Skip to main content

Networks and testnet

Point @amadeus-protocol/sdk at mainnet or testnet, get testnet AMA from the faucet, and sign transactions for the right network with TransactionBuilder or the signing functions.

The SDK talks to mainnet by default. To use testnet you change two things: the API base URL you give AmadeusSDK, and the network you sign for. Testnet signatures use their own domain, so a transaction signed for mainnet is rejected on testnet, and the other way round.

The full list of endpoints and protocol parameters is on Networks.

Networks​

NetworkType names the networks. NETWORK_URLS, NETWORK_EXPLORER_URLS and NETWORK_CONFIGS hold their URLs for mainnet and testnet. CUSTOM has no entry in these maps; it is for your own node.

NetworkTypeValueAPI base URL (baseUrl)Explorer
MAINNET'mainnet'https://mainnet-rpc.ama.one/apihttps://explorer.ama.one
TESTNET'testnet'https://testnet-rpc.ama.one/apihttps://testnet.explorer.ama.one
CUSTOM'custom'Your node's URL

NETWORK_URLS and NETWORK_CONFIGS[...].rpcUrl hold the host only, without /api. Append /api when you build a baseUrl from them.

import {
NETWORK_CONFIGS,
NETWORK_EXPLORER_URLS,
NETWORK_URLS,
NetworkType,
TESTNET_FAUCET_URL
} from '@amadeus-protocol/sdk'

console.log(NETWORK_URLS[NetworkType.TESTNET]) // 'https://testnet-rpc.ama.one' (no /api)
console.log(NETWORK_EXPLORER_URLS[NetworkType.TESTNET]) // 'https://testnet.explorer.ama.one'
console.log(NETWORK_CONFIGS[NetworkType.MAINNET]) // { rpcUrl: 'https://mainnet-rpc.ama.one', explorerUrl: 'https://explorer.ama.one' }
console.log(TESTNET_FAUCET_URL) // 'https://mcp.ama.one/testnet-faucet'

Connect to testnet​

Pass the testnet API base URL to AmadeusSDK. Every API module then reads from testnet.

import { AmadeusSDK, NETWORK_URLS, NetworkType } from '@amadeus-protocol/sdk'

// NETWORK_URLS holds hosts only: append /api for the SDK
const sdk = new AmadeusSDK({ baseUrl: `${NETWORK_URLS[NetworkType.TESTNET]}/api` })

const { stats } = await sdk.chain.getStats()
console.log(stats.height) // testnet height, e.g. 7600141

const { balance } = await sdk.wallet.getBalance(
'5kizwGYhCDy8Dev7Qw31aVutXwk4sZCK18hVwWqUdLx8X6oG338XpoSR7X9c1fMg5o'
)
console.log(balance.float, balance.symbol)

To switch an existing instance, call sdk.setBaseUrl('https://testnet-rpc.ama.one/api').

The base URL only decides where requests go. It does not change how transactions are signed; see Sign for the right network.

Get testnet AMA​

The testnet faucet is at TESTNET_FAUCET_URL, https://mcp.ama.one/testnet-faucet. It sends 100 AMA per claim, once every 24 hours per IP address. Step-by-step instructions are on Testnet faucet.

Sign for the right network​

Every Amadeus transaction is signed with BLS12-381 under a domain separation tag (DST). Mainnet and testnet use different tags, so a signature made for one network does not verify on the other and cannot be replayed there.

Network you sign forDST
NetworkType.MAINNET, NetworkType.CUSTOM or nothingAMADEUS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_TX_
NetworkType.TESTNETAMADEUS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_TX_TESTNET_

A node started in testnet mode (TESTNET=true, which includes a local testnet) verifies against the testnet tag, so sign for NetworkType.TESTNET there. CUSTOM signs with the mainnet tag. txDstForNetwork returns the tag for a network:

import { NetworkType, txDstForNetwork } from '@amadeus-protocol/sdk'

console.log(txDstForNetwork()) // 'AMADEUS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_TX_'
console.log(txDstForNetwork(NetworkType.MAINNET)) // same as above
console.log(txDstForNetwork(NetworkType.CUSTOM)) // same as above
console.log(txDstForNetwork(NetworkType.TESTNET)) // 'AMADEUS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_TX_TESTNET_'

Every signing entry point takes the network. Leave it out and it signs for mainnet.

WhereHow to pass the networkSince
new TransactionBuilder(privateKey, options){ network: NetworkType.TESTNET }; every instance method that signs uses it1.8.0
createContract(abi).connect(privateKey, network?)Second argument1.8.0
Static TransactionBuilder methods that sign (signCall, sign, buildAndSign, buildAndSignCall, buildSigned*)Optional last argument1.8.0
signContractCall(senderPrivkey, call, network?)Optional last argument1.3.0
buildAndSignRaw(signerPk, signerSk, contract, method, args, network?)Optional last argument1.3.0
signUnsigned(unsignedTx, signerSk, network?)Optional last argument1.3.0

signerSk is either the Base58 64-byte seed or the 32-byte secret key from deriveSkAndSeed64FromBase58Seed; normalizeSignerSk does the conversion. buildUnsigned, buildUnsignedFromCall and the build* methods of TransactionBuilder build a transaction without signing it, so they do not take a network.

TransactionBuilder on testnet​

Before 1.8.0, TransactionBuilder and createContract(abi).connect(privateKey) always signed with the mainnet tag. Since 1.8.0 they sign for the network you give them, and mainnet stays the default:

import { LOCKUP_PRIME_ABI, NetworkType, TransactionBuilder, createContract } from '@amadeus-protocol/sdk'

declare const senderSeed: string
declare const recipient: string

// Every signing method of this builder uses the testnet tag
const builder = new TransactionBuilder(senderSeed, { network: NetworkType.TESTNET })
const transfer = builder.transfer({ recipient, amount: 1, symbol: 'AMA' })

// Or a static method, with the network as its last argument
const staticTransfer = TransactionBuilder.buildSignedTransfer(
{ senderPrivkey: senderSeed, recipient, amount: 1, symbol: 'AMA' },
NetworkType.TESTNET
)

// Or signer-bound ABI methods
const lockupPrime = createContract(LOCKUP_PRIME_ABI).connect(senderSeed, NetworkType.TESTNET)
const checkin = lockupPrime.daily_checkin({ vaultIndex: '0' })

A transaction signed for the wrong network still fails. The node checks the nonce and balance first and the signature last, so for a funded account the rejection is invalid_signature, which the SDK throws as an AmadeusSDKError. A builder created without network signs for mainnet, so its output is rejected on testnet.

Send AMA on testnet​

A complete testnet transfer: sign it for testnet, submit it and wait for the receipt.

import {
AmadeusSDK,
AmadeusSDKError,
NETWORK_EXPLORER_URLS,
NETWORK_URLS,
NetworkType,
TransactionBuilder,
getTransactionErrorMessage,
makeTransactionUrl
} from '@amadeus-protocol/sdk'

const sdk = new AmadeusSDK({ baseUrl: `${NETWORK_URLS[NetworkType.TESTNET]}/api` })

export async function sendTestnetAma(
senderSeed: string,
recipient: string,
amount: number
): Promise<string> {
const builder = new TransactionBuilder(senderSeed, { network: NetworkType.TESTNET })
const { txPacked } = builder.transfer({ recipient, amount, symbol: 'AMA' })

try {
const { hash, receipt } = await sdk.transaction.submitAndWait(txPacked)
if (!receipt.success) {
throw new Error(getTransactionErrorMessage(receipt.result ?? 'unknown'))
}
console.log(makeTransactionUrl(hash, NETWORK_EXPLORER_URLS[NetworkType.TESTNET]))
return hash
} catch (error) {
if (error instanceof AmadeusSDKError) {
throw new Error(getTransactionErrorMessage(error.message))
}
throw error
}
}

senderSeed is the Base58 64-byte seed of an account funded from the faucet, for example from generateKeypair().privateKey or mnemonicToSeedBase58(phrase) (see Recovery phrases). amount is in AMA; transfer converts it to atomic units. Each transfer also needs 0.01 AMA free for its budget and is charged a fraction of that (see Transaction fees).

Sign a ContractCall for testnet​

signContractCall is the alternative to a builder: it signs any ContractCall ({ contract, method, args }) for the network you pass. Use it when you already hold a call, for example from buildCoinTransfer, createContract(abi).<method>(...) or the NFT builders:

import { NetworkType, buildNftCreateCollection, signContractCall } from '@amadeus-protocol/sdk'

export function createTestnetCollection(senderSeed: string) {
const call = buildNftCreateCollection({ collection: 'MYART' })
return signContractCall(senderSeed, call, NetworkType.TESTNET)
}

ABIs and the contract builders are covered in Contracts and NFTs. RISC-V smart contracts run on testnet only today; see Smart contracts.

Build now, sign later​

When the signer is somewhere else, or you build the arguments yourself, use the lower-level functions and pass the network when you sign:

import {
NetworkType,
buildAndSignRaw,
buildUnsigned,
deriveSkAndSeed64FromBase58Seed,
fromBase58,
getPublicKey,
signUnsigned,
toAtomicAma
} from '@amadeus-protocol/sdk'

export function signTestnetTransfers(senderSeed: string, recipient: string) {
const { seed64, sk } = deriveSkAndSeed64FromBase58Seed(senderSeed)
const signerPk = getPublicKey(seed64)
const args = [fromBase58(recipient), toAtomicAma(1).toString(), 'AMA']

// One step
const signed = buildAndSignRaw(signerPk, sk, 'Coin', 'transfer', args, NetworkType.TESTNET)

// Two steps: build now, sign later (for example on another device)
const unsigned = buildUnsigned(signerPk, 'Coin', 'transfer', args)
const signedLater = signUnsigned(unsigned, senderSeed, NetworkType.TESTNET)

return { signed, signedLater }
}

Next steps​