Hey devs, can someone help me with implementing a stuct within a struct. I seem to be missing something.
I have 3 structs. A, B, and C.
A can have zero to many B's,
B can have zero to many C's.
struct A {
B[] b;
string fields;
}
struct B {
C[] c;
string fields;
}
struct C {
string fields;
}
mapping (address => A) internal a;
[I think over here I'm missing a link between B and C]
Problem: I can insert into A successfully (without having to send a B), but when I try and insert into B then it says it's missing a field (which is C)
#hopethatexplainsit
Jan 9, 2023, 1:05 PM
Show code and corresponding error. Also, can't you access it like
a[address].b[index].c[index]
a[address].b[index].c[index]
Jan 9, 2023, 3:30 PM
what are you doing?
Jan 9, 2023, 3:32 PM
Working fine for me.
Jan 9, 2023, 4:03 PM
B newB = B({
c: [C({fields: "some value for fields in C"})],
fields: "some value for fields in B"
});.. try to fake it with empty values i do not get you
c: [C({fields: "some value for fields in C"})],
fields: "some value for fields in B"
});.. try to fake it with empty values i do not get you
In Solidity, fields in a struct are required unless you specify a default value for them. For example:
struct Example {
uint256 a;
uint256 b;
string c;
bool d = false;
}
uint256 a;
uint256 b;
string c;
bool d = false;
}
Example example = Example({a: 123}); // Error: missing field b
hope this help... hit inbox we discuss more if needed..
Jan 10, 2023, 6:40 AM
contract A {
address public contractB;
constructor(address _addr){
contractB = _addr;
}
function deposit() public payable {
}
function withdraw() public {
uint bal = 1 ether;
payable(contractB).transfer(bal);
}
}
contract B {
uint public count;
fallback() external payable {
if (count<=5) {
count++;
}
}
}
Why Txis failing in the following scenario:
1. Deploy contract B.
2. Deploy contract A by passing the address of contract B.
3. Deposit some ether to contract A using the deposit function. (Deposite more than 1 ether).
4. Calling withdraw function. Here Tx is failing. Why?
address public contractB;
constructor(address _addr){
contractB = _addr;
}
function deposit() public payable {
}
function withdraw() public {
uint bal = 1 ether;
payable(contractB).transfer(bal);
}
}
contract B {
uint public count;
fallback() external payable {
if (count<=5) {
count++;
}
}
}
Why Txis failing in the following scenario:
1. Deploy contract B.
2. Deploy contract A by passing the address of contract B.
3. Deposit some ether to contract A using the deposit function. (Deposite more than 1 ether).
4. Calling withdraw function. Here Tx is failing. Why?
Jan 10, 2023, 8:08 AM
I think your fallback costs more than 2300 gas
due to the fact that you added calculations to it
use contractB.call{value:1e18}("") and add success check
Jan 10, 2023, 8:17 AM
If I don't do calculation, just assign some value such as count =1 , still this is not working.
Is there any restriction of gas uses in fallback function?, even I can do the same thing through call low level function, then there is no problem with gas. Why?
Is there any restriction of gas uses in fallback function?, even I can do the same thing through call low level function, then there is no problem with gas. Why?
Jan 10, 2023, 9:17 AM
use low level call
Jan 10, 2023, 9:18 AM
Yes I can do, I am not doing project ๐คฃ๐คฃ. I am just experimenting. So I want to do this by transaction function
Jan 10, 2023, 9:19 AM
The restriction is on the .transfer you are using to send eth.
It have a hardcoded 2300 gas limit, which doesn't allow any fallback/functions to execute
Jan 10, 2023, 9:23 AM
Ohh. Thanks. Can you send me link of this concept from solidity documentation. I tried but didn't find this becuz I have also tried to debug it on remix , there was some gas problem.
Let me research again on documentation
Jan 10, 2023, 9:26 AM
Search for solidity transfer function
Jan 10, 2023, 9:27 AM
Got it. Thanks
Jan 10, 2023, 9:33 AM
https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/
Any yul masters in here?
I think we need a community๐
Jan 10, 2023, 10:55 AM
Whatโs the ideal?
Jan 10, 2023, 10:56 AM
Wdym?
Jan 10, 2023, 10:56 AM
Man, you don't have receive() function in contract B. Its basic knowledge. Contract B can't receive payments without this.
Jan 10, 2023, 10:58 AM
It can
Jan 10, 2023, 11:00 AM
Well, fallback() CAN receive Ether.
Jan 10, 2023, 11:00 AM
LOL
"basic knowledge"
Jan 10, 2023, 11:00 AM
Suppose you send a transaction with a missing function signature.
Then it would be handled by fallback(), and as it's payable here, Ether reception would also be handled just fine.
Jan 10, 2023, 11:01 AM
yeah, my bad. Fallback payable gives opportunity to receive ether. hmmm
Jan 10, 2023, 11:05 AM
Nice.
Jan 10, 2023, 11:06 AM
it's weird practice, but it's works.
Jan 10, 2023, 11:09 AM
Folks, I'm not sure if it's for you, but would you like to become better solidity devs? Obviously, yes. So join the party and start studying Yul ๐ฅ๐ฅ๐ฅ
https://t.me/yul_eth
https://t.me/yul_eth
Jan 10, 2023, 11:10 AM
pure fallback can't
where you test this code? In Remix ide?
Jan 10, 2023, 11:25 AM
Yes
Jan 10, 2023, 11:37 AM
What's yul
Jan 10, 2023, 2:30 PM
Yul is a low-level assembly language,
You can use it to optimize the code for cheaper gas usage or call low level functions.
You can use it to optimize the code for cheaper gas usage or call low level functions.
Credit to @StevengrantANT๐
Jan 10, 2023, 2:33 PM
Just saw. Thanks
But how do you integrate another language to Solidity?
But how do you integrate another language to Solidity?
Jan 10, 2023, 2:33 PM
Solidity supports assembly, it all gets compiled into bytecode at the end of the day
Jan 10, 2023, 2:35 PM
I have question guys do you all master or feel comfortable with other languages or framework? Are you specialized in solidity or you are able to do full stack?
It is just curious question as I'm trying to learn next js now and kind see the way long ๐
I mean learning solidity alone can be fast but with all the things around ๐ .. Make the learning process kind long
It is just curious question as I'm trying to learn next js now and kind see the way long ๐
I mean learning solidity alone can be fast but with all the things around ๐ .. Make the learning process kind long
Jan 10, 2023, 3:35 PM
Same same. I started with js then react then solidity. Now I went back to learn nodejs and mongo cause itโs good to know some full stack like MERN but I think there is so much more to solidity than just making tokens or nfts. Solidity by itself is a huge world.
Jan 10, 2023, 3:39 PM
I feel pretty powerful only with solidity/Js/python or at least, there isn't anything i could not do with those.
Of course having a background in IT/servers in general is a plus, as you can configure whole backends from scratch (even if sometimes using hosted solution like AWS maybe it's more safer for certain things)
Of course having a background in IT/servers in general is a plus, as you can configure whole backends from scratch (even if sometimes using hosted solution like AWS maybe it's more safer for certain things)
Jan 10, 2023, 3:43 PM
Exactly
Jan 10, 2023, 3:43 PM
100%, since i saw foundry & solidity scripting/tests, I've revaluated solidity ๐๐
https://github.com/memester-xyz/surl
Jan 10, 2023, 3:44 PM
Anyone have any idea why the withdrawal function reverts
Jan 10, 2023, 3:46 PM
Yeah I just went back to web2 stuff in case the market gets worse I can get a web2 job in the meantime. Ultimately I wanna do solidity. So much I wanna learn about it and so little time
Jan 10, 2023, 3:47 PM
Answer is already revealed above,
Jan 10, 2023, 3:47 PM
Can you direct me to it
Jan 10, 2023, 3:47 PM
web3 jobs lost volumes, as the whole market.
This give you time to learn all the web2 things you miss but don't get too easy, once the volumes kicks back in, who got more exp on web3 will have good time
This give you time to learn all the web2 things you miss but don't get too easy, once the volumes kicks back in, who got more exp on web3 will have good time
Jan 10, 2023, 3:48 PM
Read chats from here.
kiki
Jan 10, 2023, 3:48 PM
Thank you all, this is real encouragement, I really appreciate it ๐
Jan 10, 2023, 3:49 PM
Oh bro I ask this on discord as well . ๐คฃ๐คฃ
Jan 10, 2023, 3:51 PM
That's where I saw it
Jan 10, 2023, 3:52 PM
I ask the same question here as well.
Jan 10, 2023, 3:52 PM
What's about the foundry and Solidity scripting/tests that made you reevaluate Solidity?
This HTTP library can query data from like an API?
Directly into a smart contract??
Damn ๐คฉ
Directly into a smart contract??
Damn ๐คฉ
Jan 10, 2023, 3:56 PM
You can see
You cannot change them in memory, cause there is no dynamics in there.
Jan 10, 2023, 3:58 PM
Yeah. That's how I did mine too
Jan 10, 2023, 3:58 PM
Thanks Viktor ๐๐ผ
Jan 10, 2023, 3:58 PM
yep, but only in localhost of course :P
Jan 10, 2023, 4:11 PM
That's useless then โน๏ธ
Jan 10, 2023, 4:47 PM
a phrase from someone that has a closed mind
Jan 10, 2023, 4:47 PM
Well, at the moment I mean
It would be put to greater use it in a production app
Jan 10, 2023, 4:48 PM
๐๐
Jan 10, 2023, 4:52 PM
no black magic
Jan 10, 2023, 5:00 PM
you can send a telegram message with the deployed address directly within a solidity contract
seems useful to me :o
i had a little snippet to do that in js, seems it's possible in solidity /w foundry, with that library
i had a little snippet to do that in js, seems it's possible in solidity /w foundry, with that library
no bot.send_message tho, raw post api call
Jan 10, 2023, 5:20 PM
lol
Submitting the API token in a transaction or so ๐
Jan 10, 2023, 5:32 PM
bruh
it's on localhost
evm cannot access internet
Jan 10, 2023, 5:32 PM
Connecting web2 with web3 infrastructur is always stupid
Jan 10, 2023, 5:32 PM
it's an "hack" i guess, won't work on real networks
Jan 10, 2023, 5:32 PM
I mean we store some stats aswell in a database, but why using a database local
Jan 10, 2023, 5:32 PM
depend on what you need to build
Jan 10, 2023, 5:33 PM
Right now encrypting data on transaction is kinda expensive and "unsafe"
I mean if someone gets your RSA Private key, he can decrypt all messages ever been
No deleting ๐
For speed a regular PSQL database is useful
OneTimePad would be an option๐
Working on idea of having an encrypted system which has the data on the blockchain, so nobody can intercept the database or delete smth
But biggest issue is solving private key issue ๐
Jan 10, 2023, 5:35 PM