Error from the data field - Algorand

Error from the data field

post by ddev on May 28, 2020

I am getting arror from terminal that says : “built-in functions not subscriptable”.

  1. If I’m passing in these arguments in the data field, must they all come in order or order not matter?

data = {

“sender”: my_address,

“receiver”: receiver,

“fee”: params.get(‘minFee’),

“flat_fee”: True,

“amt”: 0,

“first”: params.get(‘lastRound’),

“last”: params.get(‘lastRound’) + 1000,

“note”: note,

“gen”: params.get(‘genesisID’),

“gh”: params.get(‘genesishashb64’)

}


post by fabrice on May 28, 2020

  1. Can you send us the code and the full error message?
  2. The order does not matter in a dict such as data.

post by ddev on May 28, 2020

I’ve been working around it. But here is another error I’m getting when I had to specify each parameter in the data field.

I test for the length of the addresses and it’s 58, so I’m confused.

post by liz on May 28, 2020

Not sure if this is the issue, but the line:

receiver=params.get(receiver) looks funny. If params is a dict of suggested parameters returned by the API, then there is no receiver field. Did you mean to just use receiver?

post by fabrice on May 28, 2020

Can you try to remove

receiver = params.get(receiver)

and print receiver to be sure it’s a valid address.

Note: You can copy-paste code in Forum, you just need to put them between three backquotes like ```python my python code

or ```
my result of python

It is often more convenient than images.

post by ddev on May 28, 2020

Yes I. Did. Perhaps I should not have right?

post by ddev on May 28, 2020

OK great noted. But I had explicitly specify the receiver since I want to send token from one account to another and to another account.

post by ddev on May 28, 2020

I’ve removed it but getting same error as WrongKeyLengthError: Key length must be 58

post by fabrice on May 28, 2020

Can you print sender and receiver just before the line trxn = transaction... and check those are valid addresses? You can do that by copy-pasting them in an Algorand explorer such as https://goalseeker.purestake.io/algorand/testnet

post by ddev on May 28, 2020

I tried it. They’re valid addresses as shown in Image.

But if I used the full word receiver, I get this error…

post by fabrice on May 28, 2020

This is a different error, we’re progressing.

Can you copy-paste the full code and the full reported error as a response of this post, inside a code block (i.e., between and in your post)?

post by ddev on May 28, 2020

//generateAccount.py

from algosdk import algod
from connect import Connect

accounts = {}
# To get account information
getConnect = Connect()
forAlcInfo = getConnect.connectToNetwork()

# define a function to generate 2 accounts
def generateAccounts():
    # generate accounts 1 and 2
    private_key_1, address_1 = account.generate_account()
    private_key_2, address_2 = account.generate_account()
    account_1 =  {
            "pkey": private_key_1,
            "alc_address":address_1,
            "alc_information": forAlcInfo.account_info(address_1)
        }
    account_2 = {
            "pkey": private_key_2,
            "alc_address":address_2,
            "alc_information": forAlcInfo.account_info(address_2)
        }
    # store accounts 1 and 2
    accounts["account_1"] = account_1
    accounts["account_2"] = account_2
    return (accounts)
# sendTransaction file

from algosdk import algod, transaction
from connect import Connect
from generateaccount import accounts, generateAccounts

def sendTransaction(privateKey, sender, receiver, amount):
    sndr = sender
    rcv = receiver
    amont = amount

trxn = transaction.PaymentTxn(sndr, fees, fstRound, last, genhash, rcv, amont)
    signTrxn = trxn.sign(privateKey)
    return algodClient.send_transaction(signTrxn)

post by Tim on May 28, 2020

There is some error being returned, but likely not in JSON which the SDK is expecting.

Can you try / catch the send_transaction statement and print the error it’ll show you what’s wrong.

For example:

try:
    tx_confirm = acl.send_transaction(signed_tx)
    print(tx_confirm)
except Exception as e:
    print(e)

post by ddev on May 28, 2020

Yay! It worked. @Tim that’s cool one from you. Sincerely I had used the same parameter overtime before now and it never work. Perhaps I was using it wrongly. But I learned much from the error. You really helped me a lot get over this. I almost gave up cos its been 3 days now trying to solve just one issue. But I appreciate your help a lot. Thank you and to other guys who have been helpful @fabrice @liz