-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how to deploy contract in w3vm? #133
Comments
tried to use w3.Message with InputData to deploy the contract. Simple functions can run normally, such as:
call a Complex functions failed. However, forked a exists deployed contract can call complex functions with same args. |
Understood. The default chain ID for the VM is 1. |
@temuera did you manage to deploy a contract? There is an open issue explaining how this can be done using a workaround: #112 Note, that you can also set the
You can set a custom chain config using |
Yeah, It works. Just construct an account with bytecode using state, or go with tx message. w3 is a helperfull project with great structure, But it's also brought along some inconveniences for me. 1,It's missing onSuccess and onFaild callbacks for call functions. 2,It's not compatible with the BSC version of go-eth library. This one's particularly annoying. If you don't merge the PR, I'll have to keep using my locally modified version with replace. Also, I haven't found a way yet to modify the As I continue to use it, I might come across more issues and post in this thread. |
I might have some weird use cases. but communication isn't easy 4 me (I don't speak English). Currently, I'm working on a scam token detection tool. Some scam tokens set a time bomb, where you can buy and sell tokens at BN1, but you can't sell after BN+n. That's why I'm looking for a way to switch blockNumber within the same context. I might add a /LOL |
you can set the block number when building the VM using |
see https://github.com/lmittmann/w3?tab=readme-ov-file#error-handling |
What I mean is, after executing one transaction (TX), then modifying the block number, and finally executing the next transaction. All these operations are carried out within the same context. |
Hello, I would like to ask if you have solved the problem of modifying BlockNumber on the same VM at present? |
So far a VM has a fixed BlockContext, that is set during construction. Can you tell me about your use case that would require updating it? |
` latestBlock := BlockInfo{
I don't know if I have a problem writing this, but what I need is to use the state of the current block to simulate transaction execution for the next block, because I'm developing Fraud Token Detection Tools. I was looking for a way to switch blockNumbers in the same context. |
That is possible and you don't need to change the blockCtx for that. In general I would recommend not to set the blockCtx manual, but instead simply use the option WithHeader, which derives the blockCtx from the header automatically. See the example https://pkg.go.dev/github.com/lmittmann/w3/w3vm#example-VM-TraceCalls on how to simulate (and trace) a tx in the corresponding block. Do you want to simulate in a specific block, or for a pending block? |
I want to simulate it in the pending block |
|
`while let Ok(event) = new_block_receive.recv().await {
// ** We also use the same function here to simulate a sell after a pending tx which may have changed the state of the contract
}` my approach is to refer to the rust code of a coder, which uses the current block state to simulate the transaction execution of the next block, but I want to use w3 to achieve the same function. |
Your general approach looks good to me. You should use You setup your fetcher correctly, to fetch state from the latest known block. The only thing left, is to "predict" the pending block parameters ( + nextHeader := &types.Header{
+ Number: new(big.Int).Add(latestBlock.Number(), big.NewInt(1))
+ // ...
+ }
newVM, err := w3vm.New(
w3vm.WithChainConfig(bscChainConfig),
- w3vm.WithBlockContext(blockCtx),
- w3vm.WithHeader(latestBlock.header),
+ w3vm.WithHeader(nextHeader),
w3vm.WithFetcher(w3vm.NewRPCFetcher(w3Client, latestBlock.number)),
w3vm.WithNoBaseFee()
)
if err != nil {
continue
} Note, you can also use |
I understand, thank you for your reply! |
hi all~
can anyone give a example code for deploy contract with bytecode in w3vm?
I attempted to set the account state with bytecode, but it didn't run.
The text was updated successfully, but these errors were encountered: