Discussion of the pros and cons of creating individual endpoints for fio transactions that update state.

Calling signed transaction endpoints in Typescript SDK

Our Typescript SDK currently breaks out all of the individual endpoints and you use genericAction to call the signed transaction. You refer to the documentation for the name of the SDK genericAction calls:

    const result = await user1sdk.genericAction('registerFioDomain', { 
      fioDomain: user1Domain, 
      maxFee: config.api.register_fio_domain.fee ,
      walletFioAddress: ''
    })

Our SDKs also support pushTransaction. It takes three params: action, account, and data and works for any action:

      const result = await user1sdk.genericAction('pushTransaction', {
        action: 'regdomain',
        account: 'fio.address',
        data: {
          fio_domain: user1Domain2,
          owner_fio_public_key: user1.publicKey,
          max_fee: config.api.register_fio_domain.fee,
          tpid: ''
        }
      })

On a separate note, the code for creating a signed transaction is fairly simple using our fiojs library:

const callFioApiSigned = async (endPoint, txn) => {
    info = await (await fetch(fiourl + 'get_info')).json();
    blockInfo = await (await fetch(fiourl + 'get_block', {body: `{"block_num_or_id": ${info.last_irreversible_block_num}}`, method: 'POST'})).json()
    chainId = info.chain_id;
    currentDate = new Date();
    timePlusTen = currentDate.getTime() + 10000;
    timeInISOString = (new Date(timePlusTen)).toISOString();
    expiration = timeInISOString.substr(0, timeInISOString.length - 1);
    
    transaction = {
       expiration,
       ref_block_num: blockInfo.block_num & 0xffff,
       ref_block_prefix: blockInfo.ref_block_prefix,
       actions: [{
           account: txn.account,
           name: txn.action,
           authorization: [{
               actor: txn.actor,
               permission: 'active',
           }],
           data: txn.data,
       }]
    };
  
    abiMap = new Map()
    tokenRawAbi = await (await fetch(fiourl + 'get_raw_abi', {body: '{"account_name": "' + txn.account + '"}', method: 'POST'})).json()
    abiMap.set(txn.account, tokenRawAbi)
   
    var privateKeys = [txn.privKey];
    
    const tx = await Fio.prepareTransaction({
      transaction,
      chainId,
      privateKeys,
      abiMap,
      textDecoder: new TextDecoder(),
      textEncoder: new TextEncoder()
    });
  
    pushResult = await fetch(fiourl + endPoint, {
        body: JSON.stringify(tx),
        method: 'POST',
    });
  
    json = await pushResult.json()
    return json;
  };

You can then call push_transaction directly:

const result = await callFioApiSigned('push_transaction', {
  action: 'addaddress',
  account: 'fio.address',
  actor: userA1.account,
  privKey: userA1.privateKey,
  data: {
    "fio_address": "purse@alice",
    "public_addresses": [
        {
          "chain_code": "BTC",
          "token_code": "BTC",
          "public_address": "1PMycacnJaSqwwJqjawXBErnLsZ7RkXUAs"
        }
    ],
    "max_fee": 1000000000,
    "tpid": "rewards@wallet",
    "actor": "aftyershcu22"
  }
})

Calling getters in the SDK

The typescript sdk delineates all of the getter endpoints in the main SDK. For example

            case 'getFioNames':
                return this.getFioNames(params.fioPublicKey);
            case 'getFioDomains':
                return this.getFioDomains(params.fioPublicKey, params.limit, params.offset);
            case 'getFioAddresses':
                return this.getFioAddresses(params.fioPublicKey, params.limit, params.offset);
            case 'getPendingFioRequests':
                return this.getPendingFioRequests(params.limit, params.offset);
            case 'getCancelledFioRequests':
                return this.getCancelledFioRequests(params.limit, params.offset);
            case 'getSentFioRequests':
                return this.getSentFioRequests(params.limit, params.offset);
            case 'getPublicAddress':
                return this.getPublicAddress(params.fioAddress, params.chainCode, params.tokenCode);
                
                etc...

Examples of new endpoints

Pros of using individual endpoints

Cons of using individual endpoints

Pros of single endpoint

Supporting both

It has been argued that we currently support both push_transaction (single endpoint) and FIO endpoints, so this is not an issue. The problem is that wallets are integrating and they are using individual endpoints. Thus, if we stop supporting multiple endpoints, or are slow to release them, it impacts the wallets ability to upgrade.

Thoughts on future direction

Eric:

      const json = {
        "fio_public_key": userC1.publicKey,
        "limit": 1,
        "offset": -1
      }
      result = await callFioApi("get_cancelled_fio_requests", json);