lmittmann / w3

Enhanced Ethereum Integration for Go
http://w3.cool
MIT License
179 stars 32 forks source link

how to deploy contract in w3vm? #133

Closed temuera closed 5 months ago

temuera commented 5 months ago

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.

temuera commented 5 months ago

tried to use w3.Message with InputData to deploy the contract.

Simple functions can run normally, such as:

 w3.MustNewFunc(`test(uint256 _in)`, "uint256")

call a Complex functions failed.

However, forked a exists deployed contract can call complex functions with same args.

temuera commented 5 months ago

Understood. The default chain ID for the VM is 1.

lmittmann commented 5 months ago

@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 w3.Message Func and Args attribute instead of constructing the input data manually using Func.EncodeArgs.

Understood. The default chain ID for the VM is 1.

You can set a custom chain config using w3vm.WithChainConfig.

temuera commented 5 months ago

@lmittmann

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. Even though I can work around these problems by writing more code, it's just not convenient.

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 blockNumber within the same VM context.

As I continue to use it, I might come across more issues and post in this thread.

temuera commented 5 months ago

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 SetBlockNumber function to w3vm.VM and submit a PR.

/LOL

lmittmann commented 5 months ago

I might add a SetBlockNumber function to w3vm.VM and submit a PR.

you can set the block number when building the VM using w3vm.WithHeader or w3vm.WithBlockContext`

lmittmann commented 5 months ago

1,It's missing onSuccess and onFaild callbacks for call functions. Even though I can work around these problems by writing more code, it's just not convenient.

see https://github.com/lmittmann/w3?tab=readme-ov-file#error-handling

temuera commented 5 months ago

VM

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.